Toma Tomov
Toma Tomov

Reputation: 1704

Why is form submitted 2 times Yii2

I have a form with onsubmit event:

<?php $form = ActiveForm::begin([
    'id' => 'order',
    'options' => [
        'class' => 'validation-wizard wizard-circle form-horizontal',
        'onsubmit' => 'checkStorageField()'
    ],
    'enableAjaxValidation'=>true,
    'enableClientValidation'=>true,
]); ?>

And the function which the event triggers is :

function checkStorageField(){
    alert(123)
    return false
}

But it seems that the event onsubmit is triggered 2 times because I get 2 alert on after another and the form is submitted anyway. What is my mistake?

Upvotes: 0

Views: 104

Answers (1)

Maksym Fedorov
Maksym Fedorov

Reputation: 6456

You should use events of ActiveForm

for example:

$('#order').on('beforeSubmit', function (e) {
    alert(123);
    return false;
});

Upvotes: 2

Related Questions