You are here

function webform_client_form_validate in Webform 7.4

Same name and namespace in other branches
  1. 5.2 webform.module \webform_client_form_validate()
  2. 5 webform.module \webform_client_form_validate()
  3. 6.3 webform.module \webform_client_form_validate()
  4. 6.2 webform.module \webform_client_form_validate()
  5. 7.3 webform.module \webform_client_form_validate()

Form API #validate handler for the webform_client_form() form.

1 string reference to 'webform_client_form_validate'
webform_client_form in ./webform.module
Client form generation function.

File

./webform.module, line 3005
This module provides a simple way to create forms and questionnaires.

Code

function webform_client_form_validate($form, &$form_state) {
  if (($errors = form_get_errors()) && array_key_exists('', $errors)) {

    // Prevalidation failed. The form cannot be submitted. Do not attemp futher
    // validation.
    return;
  }
  if ($form_state['webform']['preview'] && $form_state['webform']['page_count'] === $form_state['webform']['page_num']) {

    // Form has already passed validation and is on the preview page.
    return;
  }
  module_load_include('inc', 'webform', 'includes/webform.submissions');
  $node = $form['#node'];

  // Assemble an array of all past and new input values that will determine if
  // certain elements need validation at all.
  if (!empty($node->webform['conditionals'])) {
    $input_values = isset($form_state['storage']['submitted']) ? $form_state['storage']['submitted'] : array();
    $new_values = isset($form_state['values']['submitted']) ? _webform_client_form_submit_flatten($form['#node'], $form_state['values']['submitted']) : array();
    foreach ($new_values as $cid => $values) {
      $input_values[$cid] = $values;
    }

    // Ensure that all conditionally-hidden values are removed.
    $input_values = webform_get_conditional_sorter($node)
      ->executeConditionals($input_values, $form_state['webform']['page_num']);
  }
  else {
    $input_values = NULL;
  }

  // Run all #element_validate and #required checks. These are skipped initially
  // by setting #validated = TRUE on all components when they are added.
  _webform_client_form_validate($form, $form_state, 'webform_client_form', $input_values);
}