function _webform_productfield_quantity_validate in Commerce Webform 7
Same name and namespace in other branches
- 8 productfield.inc \_webform_productfield_quantity_validate()
- 7.2 productfield.inc \_webform_productfield_quantity_validate()
Validate the user entered value in the quantity field.
1 string reference to '_webform_productfield_quantity_validate'
- _webform_render_productfield in ./
productfield.inc - Implements _webform_render_component().
File
- ./
productfield.inc, line 622
Code
function _webform_productfield_quantity_validate($element, &$form_state, $form) {
$value = $form_state['values'];
foreach ($element['#parents'] as $parent) {
$value = $value[$parent];
}
$name = implode('][', $element['#parents']);
if (!isset($value) || empty($value)) {
$value = 0;
}
if (!is_numeric($value)) {
form_set_error($name, 'Quantity must be a number.');
}
elseif ($element['#required'] && $value < 1) {
form_set_error($name, 'Quantity must be greater than 0.');
}
elseif ($element['#required'] && $value < 0) {
form_set_error($name, 'Quantity must be a positive number or 0.');
}
}