You are here

function mostpopular_intervals_form_validate in Drupal Most Popular 6

File

./mostpopular.admin.inc, line 213
Defines all the administration forms for the Most Popular module.

Code

function mostpopular_intervals_form_validate($form, $form_state) {

  // Validate the intervals
  $intervals = $form_state['values']['intervals'];
  $good = FALSE;
  foreach ($intervals as $i => $inv) {
    $title = $inv['title'];
    $string = $inv['string'];
    if (empty($title)) {
      if (empty($string)) {

        // Ignore blank rows
        continue;
      }
      else {
        form_set_error("intervals][{$i}][title", t('You must specify the title to show users for this interval.'));
      }
    }
    else {
      if (empty($string) || strtotime($string) === FALSE) {
        form_set_error("intervals][{$i}][string", t("You must specify an interval that can be understood by <a href='@strtotime' target='php'>strtotime()</a>.", array(
          '@strtotime' => 'http://php.net/manual/en/function.strtotime.php',
        )));
      }
      elseif (strtotime($string) > time()) {
        form_set_error("intervals][{$i}][string", t('You must specify a negative interval relative to the current time'));
      }
      else {
        $good = TRUE;
      }
    }
  }
  if (!$good) {
    form_set_error(NULL, t('You must define at least one interval'));
  }
}