function commerce_coupon_code_validate_staged in Commerce Coupon 7.2
Form element validate callback: check for existing coupon code in form.
1 string reference to 'commerce_coupon_code_validate_staged'
- commerce_coupon_attach_ajax_coupon_entity_form in ./
commerce_coupon.module - Attach an ajax coupon entity form to a form or form fragment.
File
- ./
commerce_coupon.module, line 1933 - Provides coupon functionality for Drupal Commerce.
Code
function commerce_coupon_code_validate_staged($element, &$form_state) {
$code = $element['#value'];
$coupon_form_values = drupal_array_get_nested_value($form_state['values'], array_slice($element['#array_parents'], 0, -1));
$generate = $coupon_form_values['generate'];
if (isset($form_state['coupons']) && !$generate) {
$element_delta = $element['#array_parents'][2];
foreach ($form_state['coupons'] as $delta => $coupon) {
// Make sure that this code isn't used in one of the staged coupons.
if ($code == $coupon->code && $delta != $element_delta) {
form_set_error(implode('][', $element['#array_parents']), t('The code that you entered already exists.'));
}
}
}
}