Check for Duplicate Submissions
-
I have the CFDB7 set up, and folks can sign up for events without issue. The sign-up data is captured in the CFDB database just fine. I have one database that holds the sign in data for multiple events. The problem I have is that users often sign up twice for one particular event.
Because I hold multiple events in one database, I create a unique key (via filter) when the user signs up for an event. This way I can (in theory) search the db table and that unique key (vs an email address, say) to find if the duplicate entry exists.
All looks good in the db. However, the code to check for duplicate entry doesn’t catch the dup, and just allows the user to sign up over and over again.
Any help would be greatly appreciated. I’ve dug through this for ages, and am just (clearly) missing something.
Here’s what I am doing:
/** * @param $formName string * @param $fieldName string * @param $fieldValue string * @return bool */ function is_already_submitted2($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_username2($result, $tag) { $formName = 'Hike_Sign_Up_Form; // Change to name of the form containing this field $fieldName = 'hike_hiker_key'; // Change to your form's unique field name $errorMessage = 'Hello! You have already signed up for this hike. '; // Change to your error message $name = $tag['name']; if ($name == $fieldName) { if (is_already_submitted2($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_username2', 10, 2);
- The topic ‘Check for Duplicate Submissions’ is closed to new replies.