After clicking the submit button, FormValidation will submit the form if all the fields are valid.
If you want to do additional tasks instead of submitting the form, you can trigger the success.form.fv event:
Inside the success.form.fv event handler, if you want to submit the form after doing your custom job, just simply use the defaultSubmit() method:
The next sections demonstrates one of most frequent usage — using Ajax to submit the form.
Using Ajax to submit form data
The following code snippet uses the jQuery's serialize() method to get the form data, and then ajax() methods to send the data to the back-end endpoint:
Using Ajax to submit form data including files
Assume that the form consists of file input:
You can use FormData to collect the form data including selected files:
Please pay attention on contentType and processData options of the jQuery's ajax() method:
Setting contentType: false tells jQuery to not add Content-Type to the request
Setting processData: false tells jQuery to not convert our data (which is a FormData instance) to a string
On the server side, you can get the uploaded files under the names uploadedFiles-0, uploadedFiles-1, and so forth, depending how many files are chosen.
FormData are supported in modern browsers including IE 10+. You shouldn't use it if your application needs to support previous versions of IE such as IE 8, IE 9.
Using jQuery Form plugin
jQuery Form plugin allows us to submit the form, including sending files with an Ajax request easily.
The following snippet shows how to use jQuery Form's ajaxSubmit() method to send all form data, including selected files to the server: