/[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.5, Thu Mar 30 04:32:53 2006 UTC revision 1.6, Sun Apr 2 19:02:55 2006 UTC
# Line 1  Line 1 
1  <?php  <?php
2    
3  // $Id: multipage_form_example.module,v 1.4 2006/03/30 04:21:56 drumm Exp $  // $Id: multipage_form_example.module,v 1.5 2006/03/30 04:32:53 drumm Exp $
4    
5  /**  /**
6   * Implementation of hook_help().   * Implementation of hook_help().
# Line 203  function multipage_form_example_form_alt Line 203  function multipage_form_example_form_alt
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')) {      if ($_POST['op'] == t('Back')) {
207        $form['page']['#value']--;        $form['page']['#value']--;
208      }      }
209    
# Line 215  function multipage_form_example_form_alt Line 215  function multipage_form_example_form_alt
215      // Here we're augmenting the regular node form validation/submission with      // Here we're augmenting the regular node form validation/submission with
216      // some of our own.  Note that these are inside the conditional check for      // some of our own.  Note that these are inside the conditional check for
217      // this particular form.      // this particular form.
218      $form['#validate'] = array_merge($form['#validate'], array('multipage_form_example_validate' => array()));      $form['#validate'] = array_merge($form['#validate'], array('multipage_form_example_custom_validate' => array()));
219      $form['#submit'] = array_merge($form['#submit'], array('multipage_form_example_submit' => array()));      $form['#submit'] = array_merge($form['#submit'], array('multipage_form_example_custom_submit' => array()));
220    }    }
221    
222    return $form;    return $form;
# Line 225  function multipage_form_example_form_alt Line 225  function multipage_form_example_form_alt
225  /**  /**
226   * Validate our form.   * Validate our form.
227   */   */
228  function multipage_form_example_validate() {  function multipage_form_example_custom_validate() {
229    global $form_values;    global $form_values;
230    // validate our number, but don't bother if the back button was hit    // validate our number, but don't bother if the back button was hit
231    if (($form_values['page'] ==  3 ) && !is_numeric($form_values['fav_number']) && ($_POST['op'] != t('Back'))) {    if (($form_values['page'] ==  3 ) && !is_numeric($form_values['fav_number']) && ($_POST['op'] != t('Back'))) {
# Line 246  function multipage_form_example_pre_rend Line 246  function multipage_form_example_pre_rend
246    // Make sure it's our multipage form.    // Make sure it's our multipage form.
247    if ($form_id == 'multipage_form_example_node_form') {    if ($form_id == 'multipage_form_example_node_form') {
248      // Are we ready for the next page in our form?      // Are we ready for the next page in our form?
249      if ($next_page && isset($_POST['edit']['page']) && ($_POST['op'] != t('Back'))) {      if ($next_page && isset($_POST['edit']['page']) && ($_POST['op'] != t('Back')) && ($_POST['op'] != t('Preview'))) {
250        $form['page']['#value'] = $form['page']['#value'] + 1;        $form['page']['#value'] = $form['page']['#value'] + 1;
251      }      }
252    
# Line 301  function multipage_form_example_pre_rend Line 301  function multipage_form_example_pre_rend
301    
302  // Handles form submission.  We're just throwing our data into the variable  // Handles form submission.  We're just throwing our data into the variable
303  // table to keep things simple  // table to keep things simple
304  function multipage_form_example_submit() {  function multipage_form_example_custom_submit() {
305    global $form_values;    global $form_values;
306    foreach ($form_values as $key => $value) {    foreach ($form_values as $key => $value) {
307      if (in_array($key, array('fav_person', 'fav_person_desc', 'fav_gummi', 'fav_color', 'fav_number', 'fav_movie', 'fav_tv',))) {      if (in_array($key, array('fav_person', 'fav_person_desc', 'fav_gummi', 'fav_color', 'fav_number', 'fav_movie', 'fav_tv',))) {
308        $array[$key] = $value;        $array[$key] = $value;
309      }      }
310    }    }
311    variable_set('multipage_form_example_'. $form_values['nid'], $array);  
312        // A little hack so we can save new node info properly to the variable table
313      if (isset($form_values['nid'])) {
314        $nid = $form_values['nid'];
315      }
316      else {
317        $nid = db_result(db_query("SELECT id FROM {sequences} WHERE name = 'node_nid'"));
318      }
319    
320      variable_set('multipage_form_example_'. $nid, $array);
321  }  }
322    
323  /**  /**

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

  ViewVC Help
Powered by ViewVC 1.1.2