/[drupal]/contributions/docs/developer/examples/multipage_form_example.module
ViewVC logotype

Diff of /contributions/docs/developer/examples/multipage_form_example.module

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph | View Patch Patch

revision 1.2, Thu Mar 30 00:17:47 2006 UTC revision 1.3, Thu Mar 30 01:54:00 2006 UTC
# Line 168  function multipage_form_example_form(&$n Line 168  function multipage_form_example_form(&$n
168    return $form;    return $form;
169  }  }
170    
171    function theme_multipage_form_example_node_form($form) {
172      $content = '';
173    
174      if (in_array($form['page']['#value'], array(3,4))) {
175        $content .= '<p>'. t('Your favorite person is %person, and they %like gummi bears.', array('%person' => check_plain($form['person']['fav_person']['#value']), '%like' => ($form['person']['fav_gummi']['#value'] ? t('like') : t('don\'t like')))) .'</p>';
176      }
177    
178      if (in_array($form['page']['#value'], array(4))) {
179        $content .= '<p>'. t('Your favorite color is %color, and your favorite number is %number.', array('%color' => check_plain($form['fav_color']['#value']), '%number' => check_plain($form['fav_number']['#value'])));
180      }
181    
182      foreach (element_children($form) as $key) {
183        $content .= form_render($form[$key]);
184      }
185      return $content;
186    }
187    
188  /**  /**
189   * Implementation of hook_form_alter(). Here, we set up the 'page' field,   * Implementation of hook_form_alter(). Here, we set up the 'page' field,
190   * which keeps track of what stage the form is in.   * which keeps track of what stage the form is in.
# Line 179  function multipage_form_example_form_alt Line 196  function multipage_form_example_form_alt
196      // Determine which page of the multipage form we're on. We don't do      // Determine which page of the multipage form we're on. We don't do
197      // any incrementing here - that's something that our #pre_render'er      // any incrementing here - that's something that our #pre_render'er
198      // will do when this page of the form has successfully validated.      // will do when this page of the form has successfully validated.
199      $form['page'] = array('#type' => 'hidden', '#value' =>      $form['page'] = array(
200        isset($_POST['edit']['page']) ? $_POST['edit']['page'] : 1);        '#type' => 'hidden',
201          '#value' => isset($_POST['edit']['page']) ? $_POST['edit']['page'] : 1,
202        );
203    
204      // If back button is pressed, back up the form stage, Also, if preview      // If back button is pressed, back up the form stage, Also, if preview
205      // is hit we need to decrement the counter here to keep us on the same page.      // is hit we need to decrement the counter here to keep us on the same page.
206      if ($_POST['op'] == t('Back') || $_POST['op'] == t('Preview')) {$form['page']['#value']--;}      if ($_POST['op'] == t('Back') || $_POST['op'] == t('Preview')) {
207          $form['page']['#value']--;
208        }
209    
210      // This modifies the form for validation purposes. once validation is      // This modifies the form for validation purposes. once validation is
211      // completed, it'll be called one more time (through Drupal's Form API)      // completed, it'll be called one more time (through Drupal's Form API)
# Line 265  function multipage_form_example_pre_rend Line 286  function multipage_form_example_pre_rend
286        multipage_form_set_element_visibility($form['fav_tv'],                  in_array($form['page']['#value'], array(4)));        multipage_form_set_element_visibility($form['fav_tv'],                  in_array($form['page']['#value'], array(4)));
287      }      }
288    
     // The progress display for stuff we've already entered  
     $person_display = t('Your favorite person is %person, and they %like gummi bears.<br \>', array('%person' => check_plain($form_values['fav_person']), '%like' => ($form_values['fav_gummi'] ? t('like') : t('don\'t like'))));  
     $color_number_display = t('Your favorite color is %color, and your favorite number is %number.', array('%color' => check_plain($form_values['fav_color']), '%number' => check_plain($form_values['fav_number'])));  
   
     $form['person_display']['#value']               = in_array($form['page']['#value'], array(3,4)) ? $person_display : '';  
     $form['color_number_display']['#value']         = in_array($form['page']['#value'], array(4)) ? $color_number_display : '';  
   
289      // Buttons -- like radios, they need to be properly built in the previous stage, so here we also do the switches at      // Buttons -- like radios, they need to be properly built in the previous stage, so here we also do the switches at
290      // the last chance we have.  Notice that the type gets set to 'value' and not 'hidden', b/c hidden will screw w/      // the last chance we have.  Notice that the type gets set to 'value' and not 'hidden', b/c hidden will screw w/
291      // $_POST['op']      // $_POST['op']

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

  ViewVC Help
Powered by ViewVC 1.1.2