You are here

function publication_date_pubdate_validate in Publication Date 7.2

Same name and namespace in other branches
  1. 7 publication_date.module \publication_date_pubdate_validate()

Node edit form validation handler.

Validate the published date input.

1 string reference to 'publication_date_pubdate_validate'
publication_date_form_node_form_alter in ./publication_date.module
Implements hook_form_BASE_ID_alter().

File

./publication_date.module, line 218
Add a field to nodes containing the publication date.

Code

function publication_date_pubdate_validate($form, &$form_state) {
  if (!empty($form_state['values']['pubdate']) && is_string($form_state['values']['pubdate'])) {
    $pubdate = strtotime($form_state['values']['pubdate']);
    if ($pubdate === FALSE) {
      form_set_error('pubdate', t('The value input for field <em>Published on</em> is invalid.'));
    }

    // The date must be within the range that can be stored as a 32-bit integer.
    if ($pubdate < PUBLICATION_DATE_MIN || $pubdate > PUBLICATION_DATE_MAX) {
      form_set_error('pubdate', t('Only dates between @min and @max are supported.', array(
        '@min' => format_date(PUBLICATION_DATE_MIN, 'custom', PUBLICATION_DATE_FORMAT),
        '@max' => format_date(PUBLICATION_DATE_MAX, 'custom', PUBLICATION_DATE_FORMAT),
      )));
    }
  }
}