Quantcast
Channel: WordPress.org Forums » All Topics
Viewing all articles
Browse latest Browse all 65051

Execute client side code & validation before submit

$
0
0

Replies: 1

Hello everyone,

WHAT I NEED

I would like to perform some javascript operations when the user clicks Submit and before CF7 checks and submits the form.

If these operations are not successful (error == true), I would like to block CF7 submitting the form.

WHAT I’VE TRIED

Cosa ho provato

$('#wpcf7-form-id').submit(function(e){
	...
	if(error) { e.preventDefault(); } });
	...
}

Does not work: code is executed but if error==true, submit is not blocked

$('#wpcf7-form-id .wpcf7-form-control.wpcf7-submit').click(function(e){
	...
	if(error) { e.preventDefault(); }
	...
}

Does not work, as described above.

Of course, I’ve searched this forum, stackoverflow and wordpress stackexchange before asking.

WHAT I HAVEN’T TRIED YET

Before implementing these solutions, which require external libraries, I would like to see if there is a simpler solution:
> Use an external library like Jquery Validation: https://stackoverflow.com/a/39098271/162049
> Bypass the submit mechanis and build another one by myself: https://lampjs.wordpress.com/2017/02/17/manually-submitting-contact-form-7-ajax-and-adding-extra-fields/

Thanks for every suggestion,

Marco


Viewing all articles
Browse latest Browse all 65051