Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bootstrap form validation - Validate a form using an on click event

I'm using bootstrap form validation, and i want to validate my form using a button that is not inside the form tags.

The reasons i want to do that are:

  1. I don't want to redirect the user to other page or reload the current page, after submiting the form.

  2. I want to call to an ajax call that register a user and return an answer (fail/success).

How can I call the validate form mechanism and getting true or false in order to know if I can redirect to the ajax call.

Thank you.

like image 312
guy Avatar asked Nov 09 '22 07:11

guy


1 Answers

Just attach a jquery click event to the button outside the form tags and inside that function do someting along the lines of:

//1) Submit Form using Form's ID
$("#testForm").submit();

//2 Submit Form using Form's Name
$("form[name='myForm']").submit();

//3 Submit Form using Form's Index.
$("form:first").submit();
like image 132
rtn Avatar answered Nov 14 '22 22:11

rtn