A
A
Anton2016-05-21 15:29:19
Yii
Anton, 2016-05-21 15:29:19

How to find out in a js script if the form has passed validation?

Hello, there is a form on the page with the form there is a js file how to check this js file or the form has been validated ???

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
Kirill Arutyunov, 2016-05-21
Reytarovsky @Antonchik

https://github.com/samdark/yii2-cookbook/blob/mast...
www.mushtaqtahir.com/blog/3/yii2-ajax-form-submission
stackoverflow.com/questions/28127932/how-to-send -a...

$('body').on('beforeSubmit', ‘form#formId', function () {
     var form = $(this);
     // return false if form still have some validation errors
     if (form.find('.has-error').length) {
          return false;
     }
     // submit form
     $.ajax({
          url: form.attr('action'),
          type: 'post',
          data: form.serialize(),
          success: function (response) {
               // do something with response
          }
     });
     return false;
});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question