You are here

function node_validate in Drupal 4

Same name and namespace in other branches
  1. 5 modules/node/node.module \node_validate()
  2. 6 modules/node/node.module \node_validate()
  3. 7 modules/node/node.module \node_validate()

Perform validation checks on the given node.

3 calls to node_validate()
blogapi_blogger_edit_post in modules/blogapi.module
Blogging API callback. Modifies the specified blog node.
blogapi_blogger_new_post in modules/blogapi.module
Blogging API callback. Inserts a new blog post as a node.
node_form_validate in modules/node.module

File

modules/node.module, line 1581
The core that allows content to be submitted to the site.

Code

function node_validate($node, $form = array()) {

  // Convert the node to an object, if necessary.
  $node = (object) $node;

  // Make sure the body has the minimum number of words.
  // todo use a better word counting algorithm that will work in other languages
  if (isset($node->body) && count(explode(' ', $node->body)) < variable_get('minimum_' . $node->type . '_size', 0)) {
    form_set_error('body', t('The body of your %type is too short. You need at least %words words.', array(
      '%words' => variable_get('minimum_' . $node->type . '_size', 0),
      '%type' => node_get_name($node),
    )));
  }
  if (isset($node->nid) && node_last_changed($node->nid) > $node->changed) {
    form_set_error('changed', t('This content has been modified by another user, changes cannot be saved.'));
  }
  if (user_access('administer nodes')) {

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

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

  // Do node-type-specific validation checks.
  node_invoke($node, 'validate', $form);
  node_invoke_nodeapi($node, 'validate', $form);
}