Hi,
I'm devoloping a content type where there's a hook_form. In this hook form, I declared a field of kind select, but, when I submit the form clicking "submit" botton, the system issue the error "An illegal choice has been detected. Please contact the site administrator."

The code for the field declaration is:

...

    $form['case' . $case->cid]['status-' . $case->cid] = array(
      '#type' => 'select',
      '#title' => t('Status'),
      '#default_value' => $node->linies[$case->cid]['status'],
      '#options' => statusOptions(),
      '#description' => t('Case status.'),
      '#weight' => 0,
    );
...

function statusOptions () {
  $options_aux = db_result(db_query("SELECT global_settings FROM {content_node_field} WHERE field_name = 'field_ct_plus_status'"));

  $opt = unserialize($options_aux);
  $opt = explode(chr(10),$opt['allowed_values']);

  foreach ($opt as $key => $value) {        
    $options[$value] = $value;
  }
  return $options;
}

Can you help my?

Thank!

Ismael

Comments

anil614sagar’s picture

Hello,

I guess you are not returning proper $options array. Try this.

$options should be ideally something like below.

$options['xyz'] = 'xyz';

function statusOptions () {
$options_aux = db_query("SELECT global_settings FROM {content_node_field} WHERE field_name = 'field_ct_plus_status'");
while ($options_result = db_fetch_object($options_aux)) {
$value = $options_result->global_settings;
$options[$value] = $value;
}
return $options;
}

Cheers,
Anil Sagar,
Lead Drupal Developer,
Azri Soulutions,
http://azrisolutions.com/

ismigar’s picture

Thanck, but is important to know that the content of global_settings and allow_values is a serialize array whit the options for the select. So, before construct the array $options, it's necesary to unserialize.

In the other hand, if I print the result of call my auxiliar function whitch return select options -optionsStatus()- the result is:

~ Pendent : Pendent
~ En execució : En execució
~ Tancada : Tancada
~ Rebutjada : Rebutjada

So I think, this function is good, but I dont now, where is the problem.

Ismael