Issue: Preventing Duplicate Submissions from CF7
-
I am using the code from http://cfdbplugin.com/?page_id=904 the relevant fields I had changed to:
‘$formName = ‘Coupon Request’; // Name of the form containing this field’
‘$fieldName = ‘coupon_email’; // Set to your form’s unique field name’The code is not functioning correctly, it adds everything to the database correctly where I can see it. But it does not seem check to see if the email is already there as it should. Code is below, any ideas would be greatly appreciated.
‘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”;
$exp->export($formName, $atts);
$found = false;
while ($row = $exp->nextRow()) {
$found = true;
}
return $found;
}function my_validate_email($result, $tag) {
$formName = ‘Coupon Request’; // Name of the form containing this field
$fieldName = ‘coupon_email’; // Set to your form’s unique field name
$name = $tag[‘name’];
if($name == $fieldName){
$valueToValidate = $_POST[$name];
if (is_already_submitted($formName, $fieldName, $valueToValidate)) {
$result->invalidate($name, ‘This email has already been used for a coupon.’); // error message
}
}
return $result;
}// use this if your field is a required fields on your form
add_filter(‘wpcf7_validate_email*’, ‘my_validate_email’, 10, 2); ‘https://wordpress.org/plugins/contact-form-7-to-database-extension/
The topic ‘Issue: Preventing Duplicate Submissions from CF7’ is closed to new replies.