1

I have written a form that displays data with check boxes, I want the selected values to concatenate into a string. From the submit button the string would be passed as a URL.Inside the submit handler I tried navigating to localhost but the page doesn't navigate.I this error 'An illegal choice has been detected. Please contact the site administrator.'

Note: I am using a third party software which opens a port on the server and accepts the concatenated values.

  function basket_form($form, &$form_state) {
 // Build Breadcrumbs.
    $breadcrumb = array();
    $breadcrumb[] = l(t('Home'), '');
   // Link to current URL.
    $breadcrumb[] = l(drupal_get_title(), current_path());
   // Set Breadcrumbs.
   drupal_set_breadcrumb($breadcrumb);

   // Check for empty session.
  if (!isset($_SESSION['basket']['items'])) {
      drupal_set_title(t('Your basket is empty'));
      $form['empty'] = array(
      '#type' => 'markup',
      '#markup' => t('There is nothing in your basket at the moment.'),
     );
   }
  else {
    $form['clear'] = array(
    '#type' => 'submit',
    '#value' => t('Clear the basket'),
    '#name' => 'clear',
    '#href' => 'basket/clear',
   );

    $form['items']=array(
    '#type'=>'fieldset',
    '#title'=> t('Select from the following')
    );
    foreach ($_SESSION['basket']['items'] as $nid => $data) {
    GLOBAL $url;
    if(strlen($nid)!=0){
      $values = array(
     'biomaterial_id' => $nid
      );
     $features = chado_generate_var('biomaterialprop', $values);
     foreach($features as $f){
       if (preg_match("/bamURL/", $f->type_id->name)){
          if (preg_match("/http/", $f->value)){
             $url=$f->value;
            }
          }
       }
      if(strlen($url)!=0){
        $form['items'][$nid]['name'] = array(
        '#type' => 'checkbox',
        '#title' => t("<a href=biomaterial/$nid>$data[name]</a>"."(bam))"),
        '#options' => array (
         $url => $data['name']
       ),
     );
   }
    else{
       $form['items'][$nid]['name'] = array(
       '#type' => 'checkbox',
       '#title' => t("<a href=biomaterial/$nid>$data[name]</a>"),
     '#options' => array (
          1 => $data['name']),
      );
    }
   }
 }
   $form['submit'] = array(
      '#type' => 'submit',
      '#value' => 'IGV',
   );
  return $form;
 }

function basket_form_submit($form, &$form_state) {
    //concatenation help, I tried printing $form_state couldn't see    
     anything. 
    //"drupal_goto('http://localhost')    
    drupal_goto('http://localhost:60151/load?file=concatenated string')
   }
 }

1 Answer 1

0

Make sure you understand the processing flow of drupal forms. See an illustration here for example: https://www.drupal.org/node/165104

The basic flow is like this:

  • First request
    • Form build to represent the form to the user
    • User hits submit which results in a new request to the server
  • Second request
    • Form gets rebuild by calling the form builder (basket_form)
    • Form gets processed (validate and submit handlers are called)

The error message that you see results from the fact, that after the user hits the submit button, the form is first rebuild. Because you are using the $_SESSION to store your values (you should use the $form_state['values'] array instead) the checkboxes will not be build. And when drupal processes the form after the internal rebuild, it recognizes, that form items have been submitted that are not part of the form.

Also this might help: http://proofgroup.com/blog/2008/jul/debugging_mysterious_illegal_choice_has_been_detected_please_contact_site_administrato

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.