function _webform_productfield_required_multiple_quantities_validate in Commerce Webform 7
Same name and namespace in other branches
- 8 productfield.inc \_webform_productfield_required_multiple_quantities_validate()
- 7.2 productfield.inc \_webform_productfield_required_multiple_quantities_validate()
Validate a required multiple selection with quantity selection control. At least one sub element must have a positivie quantity set.
1 string reference to '_webform_productfield_required_multiple_quantities_validate'
- _webform_render_productfield in ./
productfield.inc - Implements _webform_render_component().
File
- ./
productfield.inc, line 669
Code
function _webform_productfield_required_multiple_quantities_validate($element, &$form_state, $form) {
if ($element['#required']) {
$form_key = $element['#webform_component']['form_key'];
foreach ($form_state['values']['submitted'][$form_key] as $product_id => $quantity) {
if ($quantity > 0) {
// At least one element has a quantity set.
return;
}
}
$name = implode('][', $element['#parents']);
form_set_error($name, t('You must choose at least one product from this selection by setting its quantity to something greater than 1'));
}
}