You are here

function _webform_edit_date_validate in Webform 7.4

Implements hook_form_id_validate().

Warns user about hiding all the date fields and not using the date picker.

1 string reference to '_webform_edit_date_validate'
_webform_edit_date in components/date.inc
Implements _webform_edit_component().

File

components/date.inc, line 138
Webform module date component.

Code

function _webform_edit_date_validate($form, &$form_state) {

  // Reduce checkbox values to simple non-associative array of values.
  form_set_value($form['extra']['exclude'], array_filter(array_values($form_state['values']['extra']['exclude'])), $form_state);

  // Note that Drupal 7 doesn't support setting errors no checkboxes due to
  // browser issues. See: https://www.drupal.org/node/222380
  if (count($form_state['values']['extra']['exclude']) == 3) {
    form_set_error('extra][exclude', 'The day, month and year can\'t all be hidden.');
  }
  if ($form_state['values']['extra']['exclude'] == array(
    'month',
  )) {
    form_set_error('extra][exclude', 'You cannot hide just the month.');
  }

  // Validate that the start and end dates are valid. Don't validate the default
  // date because with token substitution, it might not be valid at component
  // definition time. Also note that validation was introduced in 7.x-4.8 and
  // previously-defined webform may have invalid start and end dates.
  foreach (array(
    'start_date',
    'end_date',
  ) as $field) {
    if (trim($form_state['values']['extra'][$field]) && !($date[$field] = webform_strtodate('c', $form_state['values']['extra'][$field]))) {
      form_set_error("extra][{$field}", t('The @field could not be interpreted in <a href="http://www.gnu.org/software/tar/manual/html_chapter/Date-input-formats.html">GNU Date Input Format</a>.', array(
        '@field' => $form['validation'][$field]['#title'],
      )));
    }
  }
  if (!empty($date['start_date']) && !empty($date['end_date']) && $date['end_date'] < $date['start_date']) {
    form_set_error('extra][end_date', t('The End date must be on or after the Start date.'));
  }
}