function recipe_validate in Recipe 7
Same name and namespace in other branches
- 5 recipe.module \recipe_validate()
- 6 recipe.module \recipe_validate()
- 7.2 recipe.module \recipe_validate()
Implements hook_validate().
Errors should be signaled with form_set_error().
File
- ./
recipe.module, line 1323 - Contains functions for Recipe node CRUD and display.
Code
function recipe_validate($node, $form, &$form_state) {
$return = TRUE;
if (!is_numeric($form_state['values']['recipe_yield']) || $form_state['values']['recipe_yield'] <= 0) {
form_set_error('recipe_yield', t('Yield must be a valid positive integer.'));
$return = FALSE;
}
foreach ($form_state['values']['recipe_ingredients']['ing'] as $key => $ingredient) {
if (empty($ingredient['unit_key']['#value']) && !empty($ingredient['name']['#value'])) {
form_set_error("recipe_ingredients][ing][{$key}][unit_key", t("You must choose a valid unit."));
$return = FALSE;
}
}
if (!is_numeric($form_state['values']['recipe_preptime']) || $form_state['values']['recipe_preptime'] < 0) {
form_set_error('recipe_preptime', t('Preparation time must be a valid positive integer. Utilize 0 for N/A.'));
$return = FALSE;
}
if (!is_numeric($form_state['values']['recipe_cooktime']) || $form_state['values']['recipe_cooktime'] < 0) {
form_set_error('recipe_cooktime', t('Cooking time must be a valid positive integer. Utilize 0 for N/A.'));
$return = FALSE;
}
return $return;
}