You are here

function override_node_options_validate_node in Override Node Options 5

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

Perform additional node form validation normally skipped by core.

File

./override_node_options.module, line 108
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_id, $form_values) {

  // Validate the "authored by" field.
  if (!empty($form_values['name']) && !($account = user_load(array(
    'name' => $form_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_values['name'],
    )));
  }

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