0

I have a user registration form, which requires one of the fields (select list) to be populated pro grammatically from a third party service.

  // NOTE: Customize the exiting area drop down programmatically from aquarius tables
  $lang = $form['field_area']['#language'];
  $form['field_area'][$lang]['#options'] = array_merge($form['field_area'][$lang]['#options'], $rows);

This works - at least renders fine - however when I submit the form if I select anything other than the default (hardcoded) item I get a validation error:

Area: illegal value

How do I circumvent this check for this single field

Alex

8
  • You could probably hack a way to circumvent it, but I think you are getting this error because the array you're using to populate #options is something other than a format Drupal expects. What does the array look like? Jul 3, 2013 at 18:55
  • It's a standard PHP array when populated through the form builder interface: Jul 3, 2013 at 19:09
  • Through this module? By 'standard', do you mean, it looks like array(0 => 'Option 1', 1 => 'Option 2') or array('option1' => array('a', 'b', 'c'), 'option2' => array('d','e','f'))? Jul 3, 2013 at 19:16
  • Try to use drupal_map_assoc. $form['field_area'][$lang]['#options'] = drupal_map_assoc (array_merge($form['field_area'][$lang]['#options'], $rows));
    – heshanlk
    Jul 3, 2013 at 19:22
  • By the user profile module I assume? Yes it appears to be a standard (flat) PHP associative array not modified with custom drupal attributes or values. Jul 3, 2013 at 19:45

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.