You are here

function override_node_options_validate_node in Override Node Options 6

Same name and namespace in other branches
  1. 5 override_node_options.module \override_node_options_validate_node()

Perform additional node form validation normally skipped by core.

1 string reference to 'override_node_options_validate_node'
override_node_options_form_alter in ./override_node_options.module
Implements hook_form_alter().

File

./override_node_options.module, line 127
Allow users to override the default publishing options for nodes they can edit without giving them the 'administer nodes' permission.

Code

function override_node_options_validate_node($form, &$form_state) {

  // Validate the "authored by" field.
  if (!empty($form_state['values']['name']) && !($account = user_load(array(
    'name' => $form_state['values']['name'],
  )))) {

    // The use of empty() is mandatory in the context of usernames
    // as the empty string denotes the anonymous user. In case we
    // are dealing with an anonymous user we set the user ID to 0.
    form_set_error('name', t('The username %name does not exist.', array(
      '%name' => $form_state['values']['name'],
    )));
  }

  // Validate the "authored on" field. As of PHP 5.1.0, strtotime returns FALSE instead of -1 upon failure.
  if (!empty($form_state['values']['date']) && strtotime($form_state['values']['date']) <= 0) {
    form_set_error('date', t('You have to specify a valid date.'));
  }
}