Contact Form 7 – Stop Duplicate Submissions

Views: 303

<?php 
/**
 * Hook CF7 - stop duplicate submissions
 * By: Dean Williams
 * URL: https://webdesires.co.uk
 */
 
add_filter( 'wpcf7_validate', 'maybe_skip_mail2' );

function maybe_skip_mail2($result, $tags = '') {
	
	$currentformInstance  = WPCF7_ContactForm::get_current();
	$contactformsubmition = WPCF7_Submission::get_instance();

	$mail = $currentformInstance->prop('mail');
	$data = $contactformsubmition->get_posted_data();


	//stop multiple submissions
	if ( ! session_id() ) {
		session_start();
	}
	if (isset($_SESSION['cf7_form_timer'])) {
		if ($_SESSION['cf7_form_timer'] > time()) {
			echo '{"mailSent":false,"status":"validation_failed","into":"#'.$data['_wpcf7_unit_tag'].'","message":"We have received your registration. Please do not resubmit, which may result in delay in processing your request.","invalidFields":[{"into":"span.wpcf7-form-control-wrap.captcha-170","message":"We have received your registration. Please do not resubmit, which may result in delay in processing your request.","idref":null}]}';
			die();
		} else {
			$_SESSION['cf7_form_timer'] = strtotime('+1440 minute', time());
		}
	} else {
		$_SESSION['cf7_form_timer'] = strtotime('+1440 minute', time());
	}
	
	return $result;
}
?>

The above code to be added in My Custom Functions – Space X-Chimp

Author:

Leave a Reply