function node_validate
node_validate($node, $form, &$form_state)
Implements hook_validate().
Performs validation checks on the given node.
File
- modules/node/node.module, line 1011
- The core that allows content to be submitted to the site. Modules and scripts may programmatically submit nodes using the usual form API pattern.
Code
function node_validate($node, $form, &$form_state) { if (isset($node->nid) && (node_last_changed($node->nid) > $node->changed)) { form_set_error('changed', t('The content on this page has either been modified by another user, or you have already submitted modifications using this form. As a result, your changes cannot be saved.')); } // Validate the "authored by" field. if (!empty($node->name) && !($account = user_load_by_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' => $node->name))); } // Validate the "authored on" field. if (!empty($node->date) && strtotime($node->date) === FALSE) { form_set_error('date', t('You have to specify a valid date.')); } // Invoke hook_validate() for node type specific validation and // hook_node_validate() for miscellaneous validation needed by modules. Can't // use node_invoke() or module_invoke_all(), because $form_state must be // receivable by reference. $function = node_type_get_base($node) . '_validate'; if (function_exists($function)) { $function($node, $form, $form_state); } foreach (module_implements('node_validate') as $module) { $function = $module . '_node_validate'; $function($node, $form, $form_state); } }
© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/modules!node!node.module/function/node_validate/7.x