You are here

function _date_repeat_widget_validate in Date 5.2

Same name and namespace in other branches
  1. 6.2 date/date_repeat.inc \_date_repeat_widget_validate()
  2. 6 date/date_repeat.inc \_date_repeat_widget_validate()
  3. 7 date_repeat.inc \_date_repeat_widget_validate()

Validation for date repeat form element.

Create multiple values from the RRULE results. Lots more work needed here.

1 call to _date_repeat_widget_validate()
date_widget_validate in date/date_elements.inc
Handle widget processing.

File

date/date_repeat.inc, line 56
Implementation of Date Repeat API calculations for the CCK Date field.

Code

function _date_repeat_widget_validate($element) {
  global $form_values;
  $field_name = $element['#parents'][0];
  $field = $element[0]['#field'];
  $values = date_repeat_merge($element['#post'][$field_name]['rrule'], $element['rrule']);

  // If no start date was set, clean up the form and return.
  // If no repeats are set, clean up the form and return.
  if (empty($form_values[$field_name][0]['value']) || $values['FREQ'] == 'NONE') {
    form_set_value(array(
      '#parents' => array(
        $field_name,
        0,
        'rrule',
      ),
    ), NULL);
    form_set_value($element['rrule'], NULL);
    return;
  }

  // Require the UNTIL date for now.
  // The RRULE has already been created by this point, so go back
  // to the posted values to see if this was filled out.
  $error_field = implode('][', $element['#parents']) . '][rrule][UNTIL][datetime][date';
  if (empty($values['UNTIL']['datetime'])) {
    form_set_error($error_field, t('The UNTIL value is required for repeating dates.'));
  }
  if (form_get_errors()) {
    return;
  }

  // If the rule, the start date, or the end date have changed, re-calculate
  // the repeating dates, wipe out the previous values, and populate the
  // field with the new values.
  // TODO
  // Is it right to not do anything unless there are changes? Will that
  // confuse anyone? Commenting that out for now...
  $rrule = $form_values[$field_name]['rrule'];
  if (!empty($rrule)) {
    $item = $form_values[$field_name][0];
    $value = date_repeat_build_dates($rrule, $values, $field, $item);
    form_set_value($element, $value);
  }
  else {

    // If no changes are needed, move the RRULE back to the zero value
    // item of the field.
    form_set_value(array(
      '#parents' => array(
        $field_name,
        0,
        'rrule',
      ),
    ), $rrule);
    form_set_value($element['rrule'], NULL);
  }
}