node_example_validate
- Versions
- 4.6 – 7
node_example_validate(&$node)
Implementation of hook_validate().
Our "quantity" field requires a number to be entered. This hook lets us ensure that the user entered an appropriate value before we try inserting anything into the database.
Errors should be signaled with form_set_error().
Code
developer/examples/node_example.module, line 140
<?php
function node_example_validate(&$node) {
if ($node->quantity) {
if (!is_numeric($node->quantity)) {
form_set_error('quantity', t('The quantity must be a number.'));
}
}
else {
// Let an empty field mean "zero."
$node->quantity = 0;
}
}
?>Login or register to post comments 