function farm_soil_amendment_form_validate in farmOS 7
Soil amendment quick form validate.
File
- modules/
farm/ farm_soil/ farm_soil.farm_quick.amendment.inc, line 477 - Farm soil amendment quick form.
Code
function farm_soil_amendment_form_validate($form, &$form_state) {
// Alias $form_state['values']['amendment'] for easier use.
$form_values = array();
if (!empty($form_state['values']['amendment'])) {
$form_values =& $form_state['values']['amendment'];
}
// If the area measurement type is "dimensions", length and width are
// required.
if (!empty($form_values['area']['measurement']) && $form_values['area']['measurement'] == 'dimensions') {
if (empty($form_values['area']['size']['length']) || !is_numeric($form_values['area']['size']['length'])) {
form_set_error('amendment][area][size][length', t('Area length is required.'));
}
if (empty($form_values['area']['size']['width']) || !is_numeric($form_values['area']['size']['width'])) {
form_set_error('amendment][area][size][width', t('Area width is required.'));
}
}
// Ensure that the area percentage is between 1 and 100.
$percentage = $form_values['application']['percentage'];
if ($percentage < 1 || $percentage > 100) {
form_set_error('amendment][application][percentage', t('Percentage must be between 1 and 100.'));
}
// If the broadcast method is "Other", require notes.
$method = $form_values['application']['method'];
$notes = $form_values['notes']['other']['value'];
if ($method == 'Other' && empty($notes)) {
form_set_error('amendment][notes][other][value', t('Describe the method of application in the "Other notes" field.'));
}
}