check box with dynamic content and error with submit handler 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, &amp;$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' =&gt; 'markup',
      '#markup' =&gt; t('There is nothing in your basket at the moment.'),
     );
   }
  else {
    $form['clear'] = array(
    '#type' =&gt; 'submit',
    '#value' =&gt; t('Clear the basket'),
    '#name' =&gt; 'clear',
    '#href' =&gt; 'basket/clear',
   );

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

function basket_form_submit($form, &amp;$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')
   }
 }
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