[Contact-Form 7] Email Validation error shows up incorrectly
-
We use contact forms to allow our hiking club members to sign up for hikes. Each hike has its’ own form that ties to a specific event (date & time). This works like a charm.
We added the ability to filter a submission by the user-name, via the “Add Shortcodes Actions and Filters” Plug in. (We allow multiple users to share email addresses (ie husband and wife) – so need to check the sign up via user name. )
This works – however along with the message that a user is already logged in, I get a validation error message on the user name.
Here is the CFDB filter (via the plug in):
/** * @param $formName string * @param $fieldName string * @param $fieldValue string * @return bool */ function is_already_submitted($formName, $fieldName, $fieldValue) { require_once(ABSPATH . 'wp-content/plugins/contact-form-7-to-database-extension/CFDBFormIterator.php'); $exp = new CFDBFormIterator(); $atts = array(); $atts['show'] = $fieldName; $atts['filter'] = "$fieldName=$fieldValue"; $atts['unbuffered'] = 'true'; $exp->export($formName, $atts); $found = false; while ($row = $exp->nextRow()) { $found = true; } return $found; } /** * @param $result WPCF7_Validation * @param $tag array * @return WPCF7_Validation */ function my_validate_email($result, $tag) { $formName = 'San Tan - Moonlight Trail (Short) - 2 Nov 2016'; // Change to name of the form containing this field $fieldName = 'your-name'; // Change to your form's unique field name $errorMessage = 'You have already registered for this hike.'; // Change to your error message $name = $tag['name']; if ($name == $fieldName) { if (is_already_submitted($formName, $fieldName, $_POST[$name])) { $result->invalidate($tag, $errorMessage); } } return $result; } // use the next line if your field is a **required text** field add_filter('wpcf7_validate_text*', 'my_validate_email', 10, 2);
Questions:
1. How to stop the validation error from showing up when a user tries to register more than once?
2. If the filter is set to look a specific form name, why does it hit anytime someone tries to register for a hike? ie it will tell me I have already signed up for a hike when I haven’t.
Thanks for any thoughts and pointers.
Cheers
- The topic ‘[Contact-Form 7] Email Validation error shows up incorrectly’ is closed to new replies.