Fix for Fix for Code

  1. <?php  
  2. /**
  3.  * Implementation of hook_form_alter().
  4.  * @see http://api.drupal.org/api/function/hook_form_alter
  5.  * We add a few custom fields to the default Drupal contact form
  6.  */
  7. function hookContact_form_contact_mail_page_alter(&$form, $form_state) {
  8.         $form['contact_info'] = array(
  9.                 '#tree' => TRUE,
  10.                 '#prefix' => '<div id="wrapper-infos">',
  11.                 '#suffix' => '</div>'
  12.                 '#value' => isset($form_state['storage']['choix']) ? hookContact_subForm($form_state['storage']['choix']) : '',
  13.         );
  14.  
  15.         $form['choix'] = array(
  16.                 '#type' => 'radios',
  17.                 '#title' => t('Type de contact'),
  18.                 '#default_value' => $form_state['values']['choix'],
  19.                 '#options' => array(
  20.                         'mail' => 'mail',
  21.                         'tel' => 'téléphone',
  22.                 ),     
  23.                 '#ahah' => array(
  24.                         'event'   => 'change',
  25.                         'path'    => 'contact/js/addInfos',
  26.                         'wrapper' => 'wrapper-infos',                  
  27.                         'methode' => 'prepend',        
  28.                 ),
  29.                 '#required' => TRUE,
  30.         );
  31.  
  32.         $form['copy'] = array(
  33.                 '#type' => 'checkbox',
  34.         '#title' => t('Send yourself a copy.'),
  35.     );
  36.        
  37.          
  38.         // reorder the elements in the form to include the elements being inserted
  39.         $order = array('contact_information', 'name', 'entreprise', 'mail', 'choix', 'contact_info', 'subject', 'message', 'copy', 'submit');
  40.         foreach($order as $key => $field) {
  41.                 $form[$field]['#weight'] = $key;
  42.         }
  43.  
  44.    $form['#submit'] = 'mysubmit_handler';
  45. }
  46.  
  47. function mysubmit_handler($form, &$form_state) {
  48.   if (empty($form_state['storage']['choix']) {
  49.     // This will rebuild the form.
  50.     $form_state['storage']['choix'] = $form_state['values']['choix'];
  51.   }
  52. }

Submit Fix

Any tags you'd like to associate with your code, delimitered by commas (example: Views, CCK, Module, etc).
Select the syntax highlighting mode to use.