/[drupal]/drupal/includes/form.inc
ViewVC logotype

Diff of /drupal/includes/form.inc

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

revision 1.401 by dries, Wed Nov 18 18:51:11 2009 UTC revision 1.402 by dries, Sat Nov 21 14:06:45 2009 UTC
# Line 1  Line 1 
1  <?php  <?php
2  // $Id: form.inc,v 1.400 2009/11/16 05:11:01 webchick Exp $  // $Id: form.inc,v 1.401 2009/11/18 18:51:11 dries Exp $
3    
4  /**  /**
5   * @defgroup forms Form builder functions   * @defgroup forms Form builder functions
# Line 104  function drupal_get_form($form_id) { Line 104  function drupal_get_form($form_id) {
104   *     - file: An optional include file that contains the form and is   *     - file: An optional include file that contains the form and is
105   *       automatically loaded by form_get_cache(). Defaults to the current menu   *       automatically loaded by form_get_cache(). Defaults to the current menu
106   *       router item's 'file' definition, if existent.   *       router item's 'file' definition, if existent.
107     *   - storage: An array that may be used to store information related to the
108     *     processed data in the form, which can be accessed and used within the
109     *     same page request, but also persist across multiple steps in a multi-step
110     *     form.
111     *   - rebuild: Normally, after the entire form processing is completed and
112     *     submit handlers ran, a form is considered to be done and
113     *     drupal_redirect_form() will redirect the user to a new page using a GET
114     *     request (so a browser refresh does not re-submit the form). However, if
115     *     'rebuild' has been set to TRUE, then a new copy of the form is
116     *     immediately built and sent to the browser; instead of a redirect. This is
117     *     used for multi-step forms, such as wizards and confirmation forms. Also,
118     *     if a form validation handler has set 'rebuild' to TRUE and a validation
119     *     error occurred, then the form is rebuilt prior to being returned,
120     *     enabling form elements to be altered, as appropriate to the particular
121     *     validation error.
122   *   - input: An array of input that corresponds to $_POST or $_GET, depending   *   - input: An array of input that corresponds to $_POST or $_GET, depending
123   *     on the 'method' chosen (see below).   *     on the 'method' chosen (see below).
124   *   - method: The HTTP form method to use for finding the input for this form.   *   - method: The HTTP form method to use for finding the input for this form.
# Line 224  function drupal_build_form($form_id, &$f Line 239  function drupal_build_form($form_id, &$f
239    // the form will simply be re-rendered with the values still in its    // the form will simply be re-rendered with the values still in its
240    // fields.    // fields.
241    //    //
242    // If $form_state['storage'] or $form_state['rebuild'] has been set    // If $form_state['rebuild'] has been set and the form has been submitted, we
243    // and the form has been submitted, we know that we're in a complex    // know that we're in a multi-part process of some sort and the form's
244    // multi-part process of some sort and the form's workflow is NOT    // workflow is not complete. We need to construct a fresh copy of the form,
245    // complete. We need to construct a fresh copy of the form, passing    // passing in the latest $form_state in addition to any other variables passed
   // in the latest $form_state in addition to any other variables passed  
246    // into drupal_get_form().    // into drupal_get_form().
247    if ((!empty($form_state['storage']) || $form_state['rebuild']) && $form_state['submitted'] && !form_get_errors()) {    if ($form_state['rebuild'] && $form_state['submitted'] && !form_get_errors()) {
248      $form = drupal_rebuild_form($form_id, $form_state);      $form = drupal_rebuild_form($form_id, $form_state);
249    }    }
250    
# Line 255  function form_state_defaults() { Line 269  function form_state_defaults() {
269      'rebuild' => FALSE,      'rebuild' => FALSE,
270      'redirect' => NULL,      'redirect' => NULL,
271      'build_info' => array(),      'build_info' => array(),
272      'storage' => NULL,      'storage' => array(),
273      'submitted' => FALSE,      'submitted' => FALSE,
274      'programmed' => FALSE,      'programmed' => FALSE,
275      'cache'=> FALSE,      'cache'=> FALSE,
# Line 758  function drupal_validate_form($form_id, Line 772  function drupal_validate_form($form_id,
772   * - If $form_state['programmed'] is TRUE, the form submission was usually   * - If $form_state['programmed'] is TRUE, the form submission was usually
773   *   invoked via drupal_form_submit(), so any redirection would break the script   *   invoked via drupal_form_submit(), so any redirection would break the script
774   *   that invoked drupal_form_submit().   *   that invoked drupal_form_submit().
775   * - If $form_state['rebuild'] is TRUE or $form_state['storage'] is populated,   * - If $form_state['rebuild'] is TRUE, the form needs to be rebuilt without
  *   the form is most probably a multi-step form and needs to be rebuilt without  
776   *   redirection.   *   redirection.
777   *   *
778   * @param $form_state   * @param $form_state
# Line 773  function drupal_redirect_form($form_stat Line 786  function drupal_redirect_form($form_stat
786    if (!empty($form_state['programmed'])) {    if (!empty($form_state['programmed'])) {
787      return;      return;
788    }    }
789    // Skip redirection for multi-step forms.    // Skip redirection if rebuild is activated.
790    if (!empty($form_state['rebuild']) || !empty($form_state['storage'])) {    if (!empty($form_state['rebuild'])) {
791      return;      return;
792    }    }
793    // Skip redirection if it was explicitly disallowed.    // Skip redirection if it was explicitly disallowed.
# Line 3161  function batch_process($redirect = NULL, Line 3174  function batch_process($redirect = NULL,
3174   * Retrieves the current batch.   * Retrieves the current batch.
3175   */   */
3176  function &batch_get() {  function &batch_get() {
3177    $batch = &drupal_static(__FUNCTION__, array());    // Not drupal_static(), because Batch API operates at a lower level than most
3178      // use-cases for resetting static variables, and we specifically do not want a
3179      // global drupal_static_reset() resetting the batch information. Functions
3180      // that are part of the Batch API and need to reset the batch information may
3181      // call batch_get() and manipulate the result by reference. Functions that are
3182      // not part of the Batch API can also do this, but shouldn't.
3183      static $batch = array();
3184    return $batch;    return $batch;
3185  }  }
3186    

Legend:
Removed from v.1.401  
changed lines
  Added in v.1.402

  ViewVC Help
Powered by ViewVC 1.1.3