How can I trigger form validation with jQuery/Javascript without submitting the form?

By: Bret Hummel | Asked: 06/23/2022
ForumsCategory: How-toHow can I trigger form validation with jQuery/Javascript without submitting the form?
Bret Hummel asked 2 years ago

I've got a form that I'm using to capture payment info. I am capturing the user's click on the Submit button, preventing the default submission, then doing some work with the data in the form to submit the payment to a payment gateway's API. I need to wait to get a response from that API before then calling the standard submit on the form.
The ONE piece of this puzzle that I'm missing is how to trigger form validation from my jQuery to determine whether all the fields are valid BEFORE submitting to the payment API. I have been searching for a method to do so.
Has anyone done something similar, or knows of a function I can call to validate the form? I've been searching extensively and have not stumbled on the answer yet with the right keywords, or the answer just isn't out there for me to find yet!
Any help that will point me in the right direction is appreciated!

2 Answers
Victor Font answered 2 years ago

Do you have jQuery form validation enabled or are you validating on the server? If you’re validating on the server, you shouldn’t have to call anything. Validation should still occur on final submit. 

Bret Hummel replied 2 years ago

The form is set to validate with Javascript, which is what I want, I just want to call a function or something with jQuery to initiate it when I need it. Does that make sense?

Victor Font replied 2 years ago

<p>I never had a reason to research how Formidable’s jQuery validation works, but it has to bound to field events when they fire. There are only so many field events that can be used like blur or change. I would test a field by triggering one of those events in the console.</p>

Fernando Drabik replied 2 years ago

@Bret Hummel I have the EXACT same scenario and issue, need to validate a few things before I can send the payment (with the additional data) have you found a way to trigger the form validation via JS? I can confidently guess you are trying to integrate with stripe lol. Thanks so much

Adam Wolfs answered 2 years ago
Is it an issue if the submit button is clicked? if not, you could likely run a function that is similar to:
$(".frm_submit").trigger('click'); or $("form.class").trigger('submit');

Making the Best WordPress Plugin even better - Together

Take on bigger projects with confidence knowing you have access to an entire community of Formidable Experts and Professionals who have your back when the going gets tough. You got this!
Join the community
crossarrow-right