Validation failure clears form fields
-
Hi,
First thanks for the great plugin donation to the community – it performs a critical function very well.
One issue I have found is that if my custom add-to-cart validation fails, the custom form field values are cleared when the form is redisplayed with the validation error message. I am using the cloning fields feature (which is fantastic) and the correct number of custom form fields appear – they just don’t contain any values.
Is it possible to get the submitted values to show in the form again?
My validation code is:
add_action('woocommerce_add_to_cart_validation', array($this, 'validate_order_meta_data'), 10, 3); function validate_order_meta_data($valid, $product_id, $quantity) { $values = array(); // for each quantity of item added to cart check whether the meta value is unique for ($i = 0; $i < $quantity; $i++) { // request params are built from the field name and a base 1 index $request_key_index = $i + 1; $request_key = "email_$request_key_index"; if (isset($_REQUEST[$request_key])) { $value = $_REQUEST[$request_key]; // check for duplication if (in_array($value, $values)) { wc_add_notice("Value $value appears multiple times", 'error'); $valid = false; } else { $values[] = $value; } } } return $valid; }
I’m using plugin version 1.2.4 and WordPress 4.3.1
Thanks,
Dan.
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Validation failure clears form fields’ is closed to new replies.