returning to the same code a second time doesn't have the $form_values argument set

  1. function wmv_mail_form($form_values = NULL) {
  2.   global $user;
  3.  
  4.   // unset($form);
  5.   $form['#multistep'] = TRUE;
  6.  
  7.   if ($form_values == null) {
  8.     print_r($form);
  9.   }
  10.  
  11.   if (isset($form_values)) {
  12.     drupal_set_message('Tweede keer');
  13.     // this is at least already the second time that
  14.     // this form gets called
  15.     $step = $form_values['step'];
  16.     switch($step) {
  17.       case 1 :
  18.         // this is after a submit the first time, so
  19.         // that submit action is still to be confirmed
  20.         $form['step'] = array(
  21.           '#type'  => 'hidden',
  22.           '#value' => $step + 1
  23.         );
  24.  
  25.         $form['stepindicatie'] = array(
  26.           '#type'  => 'item',
  27.           '#value' => 'Stap 2 van 3'
  28.         );
  29.  
  30.         $form['submit'] = array(
  31.           '#type'          => 'submit',
  32.           '#value'         => t('Naar stap 3')
  33.         );
  34.         break;
  35.  
  36.       case 2 :
  37.         break;
  38.     }
  39.     return $form;
  40.  
  41.   } else {
  42.     // this is the very first time the form is called
  43.     $step = 1;
  44.     $form['step'] = array(
  45.       '#type'  => 'hidden',
  46.       '#value' => $step
  47.     );
  48.     // drupal_add_js(
  49.     //   drupal_get_path('module', 'wmv') . '/sitejs.js');
  50.     drupal_set_message('Eerste keer');
  51.     $form['stepindicatie'] = array(
  52.       '#type'  => 'item',
  53.       '#value' => 'Stap ' . $step . ' van 3'
  54.     );
  55.     $rsresult = db_result(
  56.       db_query(
  57.         "SELECT SpecialeBevoegdheden FROM {wmv_gebruiker} WHERE DrupalID = %d",
  58.         $user->uid)
  59.     );
  60.  
  61.     $endresult['own'] = t('Mijzelf');
  62.     if ($rsresult != "") {
  63.       foreach (explode(',', $rsresult) as $bevoegdheid) {
  64.         $endresult[$bevoegdheid] = $bevoegdheid;
  65.       }
  66.       $form['hoedanigheid'] = array(
  67.         '#type'          => 'fieldset',
  68.         '#collapsible'   => FALSE,
  69.         '#title'         => t('Mail versturen in de hoedanigheid van : '),
  70.       );
  71.       $form['hoedanigheid']['keuzes'] = array(
  72.         '#type'          => 'select',
  73.         '#options'       => $endresult,
  74.         '#description'   => t(''),
  75.         '#default_value' => 'own'
  76.       );
  77.     }
  78.  
  79.     $form['aan'] = array(
  80.       '#type'          => 'fieldset',
  81.       '#collapsible'   => FALSE,
  82.       '#title'         => t('Aan : '),
  83.     );
  84.     $form['aan']['keuzesaan'] = array(
  85.       '#type'          => 'radios',
  86.       '#options'       => array('groep' => t('Groep'), 'lid' => t('WMV-lid')),
  87.       '#description'   => t(''),
  88.       '#default_value' => 'lid',
  89.       '#attributes'    => array('onclick' =>
  90.             'add_js_code_to_show_and_hide("aan");')
  91.     );
  92.  
  93.     // fill the combobox with the values of the members
  94.     $ledenarray = array();
  95.     $result = db_query("SELECT Naam, Voornaam FROM {wmv_gebruiker} " .
  96.                        "ORDER BY Naam, Voornaam");
  97.     while ($lidentry = db_fetch_object($result)) {
  98.       $ledenarray[] = $lidentry->Naam . ' ' . $lidentry->Voornaam;
  99.     }
  100.     $form['aan']['comboledenaan'] = array(
  101.       '#type'          => 'select',
  102.       '#options'       => $ledenarray,
  103.       '#description'   => t(''),
  104.       '#default_value' => 0,
  105.       '#multiple'      => false
  106.     );
  107.  
  108.     // fill the combobox with the values of the groups
  109.     // first part : all OWN groups
  110.     $groepenarray = array();
  111.     $result = db_query("SELECT GroepsNaam FROM {wmv_groepen} WHERE OwnerDrupalID = %d " .
  112.                       "ORDER BY GroepsNaam", $user->uid);
  113.     while ($groepentry = db_fetch_object($result)) {
  114.       $groepenarray[] = $groepentry->GroepsNaam;
  115.     }
  116.  
  117.     // second part : all COMMON groups
  118.     $result = db_query("SELECT GroepsNaam FROM {wmv_groepen} WHERE OwnerDrupalID = 0 " .
  119.                       "ORDER BY SorteerVeld");
  120.     $gevonden = FALSE;
  121.     while ($groepentry = db_fetch_object($result)) {
  122.       if (!$gevonden) {
  123.         $gevonden = TRUE;
  124.         if (count($groepenarray) > 0) {
  125.           $groepenarray[] = '---------';
  126.         }
  127.       }
  128.       $groepenarray[] = $groepentry->GroepsNaam;
  129.     }
  130.     if (count(($groepenarray) > 0)) {
  131.       $form['aan']['combogroepenaan'] = array(
  132.         '#type'          => 'select',
  133.         '#options'       => $groepenarray,
  134.         '#description'   => t(''),
  135.         '#default_value' => 0,
  136.         '#multiple'      => false
  137.       );
  138.     }
  139.  
  140.     $form['cc'] = array(
  141.       '#type'          => 'fieldset',
  142.       '#collapsible'   => FALSE,
  143.       '#title'         => t('CC : '),
  144.     );
  145.     $form['cc']['keuzescc'] = array(
  146.       '#type'          => 'radios',
  147.       '#options'       => array('groep' => t('Groep'), 'lid' => t('WMV-lid')),
  148.       '#description'   => t(''),
  149.       '#default_value' => 'groep',
  150.       '#attributes'    => array('onclick' =>
  151.             'add_js_code_to_show_and_hide("cc");')
  152.     );
  153.     $form['cc']['comboledencc'] = array(
  154.       '#type'          => 'select',
  155.       '#options'       => $ledenarray,
  156.       '#description'   => t(''),
  157.       '#default_value' => 0,
  158.       '#multiple'      => false
  159.     );
  160.     if (count(($groepenarray) > 0)) {
  161.       $form['cc']['combogroepencc'] = array(
  162.         '#type'          => 'select',
  163.         '#options'       => $groepenarray,
  164.         '#description'   => t(''),
  165.         '#default_value' => 0,
  166.         '#multiple'      => false
  167.       );
  168.     }
  169.  
  170.     $form['onderwerp'] = array(
  171.       '#type'          => 'fieldset',
  172.       '#collapsible'   => FALSE,
  173.       '#title'         => t('Onderwerp : '),
  174.     );
  175.     $form['onderwerp']['tekstveld'] = array(
  176.       '#type'          => 'textfield',
  177.       '#default_value' => t('')
  178.     );
  179.  
  180.     $form['tekst'] = array(
  181.       '#type'          => 'fieldset',
  182.       '#collapsible'   => FALSE,
  183.       '#title'         => t('Tekst : '),
  184.     );
  185.     $form['tekst']['tekstarea'] = array(
  186.       '#type'          => 'textarea',
  187.       '#default_value' => t(''),
  188.       '#rows'          => 5
  189.     );
  190.  
  191.     $form['attachment'] = array(
  192.       '#type'          => 'fieldset',
  193.       '#collapsible'   => FALSE,
  194.       '#title'         => t('Bestand toevoegen : '),
  195.     );
  196.     $form['attachment']['filebutton'] = array(
  197.       '#type'          => 'file',
  198.       '#size'          => 50
  199.       // '#description'   => t('')
  200.       // '#title'         => t('')
  201.       // '#text'          => t('')
  202.     );
  203.     // needed because the 'file' type is being used in this form :
  204.     $form['#attributes']['enctype'] = 'multipart/form-data';
  205.  
  206.     $form['eigenadres'] = array(
  207.       '#type'          => 'fieldset',
  208.       '#collapsible'   => FALSE,
  209.       '#title'         => t('Eigen email adres in BCC: plaatsen'),
  210.     );
  211.     $form['eigenadres']['selectie'] = array(
  212.       '#type'          => 'checkboxes',
  213.       '#description'   =>
  214.         t('Vink dit veld aan indien deze mail ook naar jouw eigen emailadres ' .
  215.           'moet worden gezonden'),
  216.       '#options'       => array(t(''))
  217.       // '#text'          => t('')
  218.     );
  219.  
  220.     $form['submit'] = array(
  221.       '#type'          => 'submit',
  222.       '#value'         => t('Naar stap') . ' ' . ($step + 1)
  223.     );
  224.  
  225.     $form['#redirect'] = false;
  226.  
  227.     return $form;
  228.   }
  229. }