Google help on software/programming And Windows Tricks: Remove Duplicate Entry in Contact Form 7

helponsoftware

Friday 28 August 2015

Remove Duplicate Entry in Contact Form 7

add_filter( 'wpcf7_validate', 'email_already_in_db', 10, 2 );
function email_already_in_db ( $result, $tags ) {
// retrieve the posted email
$form = WPCF7_Submission::get_instance();
$email = $form->get_posted_data('email');
// if already in database, invalidate
if( is_already_submitted('Contact form 1' ,'email',$email ) )
$result->invalidate('email', 'Your email exists in our database');
// return the filtered value
return $result;
}
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;
}
Just set the field name, and form name in above function.

No comments:

Post a Comment