noecs
noecs

Reputation: 25

How to get the result of Yii2 form verification

Sorry,I use a translation tool to communicate.

<?php
$this->registerJs("
    $(function () {
        $('#send-button').click(function(){
        $('#form-signup').data('yiiActiveForm').submitting = false;
        $('#form-signup').yiiActiveForm('validateAttribute', 'signupform-username');
    });
});
", \yii\web\View::POS_END);
?>

The above is my code. When the page button is clicked, the verification of the specified field is triggered. But I do not know how to get the verification passed. Thanks for you help

Upvotes: 0

Views: 138

Answers (1)

Ziya Vakhobov
Ziya Vakhobov

Reputation: 465

You should not target the button. Target to the form, then you can easily get form events like submit, validation and beforeValidation . Here is example

$("#my-form")//is your form

$("#my-from").yiiActiveForm('validate') //validation event

$('#my-form').on('afterValidate', function (event, messages, errorAttributes) {
  //this event afterValidate
});
$('#my-form').on('beforeValidate', function (event, messages, errorAttributes) {
  //this event afterValidate
});

Upvotes: 2

Related Questions