As for Contact Form 7 to validate field values from a pre-prepared base?

There is a manually generated database of promotional codes that are printed for distribution offline.
It is necessary to form checked that you entered the correct promo code in the appropriate field by comparing with the list. If the code is entered correctly, the form with all the data is sent in the mail.
How to create a form, add fields and send email - this is clear.
The question is how to add field codes to valderrobles according to a given list?
June 10th 19 at 15:25
1 answer
June 10th 19 at 15:27
Thanks, I read it. But it is not clear from the manual how to set it so that worked for a list of the 100 promo codes, for example. Using "or" to enumerate each? I'm just not good at programming. - Emelie.Keebl commented on June 10th 19 at 15:30
I think You will approach the function in_array.
add_filter('wpcf7_validate_text*', 'custom_code_confirmation_validation_filter', 20, 2);
add_filter('wpcf7_validate_text', 'custom_code_confirmation_validation_filter', 20, 2);

custom_code_confirmation_validation_filter function($result, $tag) {
 if ('your-code' == $tag->name) {
 $codes = array('123', '234', '765', '999');
 $your_code = isset($_POST['your-code']) ? trim($_POST['your-code']) : ";

 if (!in_array($your_code, $codes)) {
 $result->invalidate($tag, "Invalid promo code");
}
}

 return $result;
}
- alexandrea_Vandervo commented on June 10th 19 at 15:33

Find more questions by tags WordPress