function recipe_validate in Recipe 5
Same name and namespace in other branches
- 6 recipe.module \recipe_validate()
- 7.2 recipe.module \recipe_validate()
- 7 recipe.module \recipe_validate()
Implementation of hook_validate().
Errors should be signaled with form_set_error().
File
- ./
recipe.module, line 937 - recipe.module - share recipes for drupal 5.x
Code
function recipe_validate(&$node) {
if (!$node->ingredients) {
return;
}
$ingredients = array();
foreach ($node->ingredients as $key => $ingredient) {
$ingredient = (object) $ingredient;
if (!isset($ingredient->quantity)) {
$ingredient = recipe_parse_ingredient_string($ingredient->name);
}
if ($ingredient->name && _in_array($ingredient, $ingredients)) {
form_set_error("recipe", t('Duplicate ingredients are not allowed.'));
}
else {
$ingredients[] = $ingredient;
}
$node->ingredients[$key] = $ingredient;
}
}