Answer the question
In order to leave comments, you need to log in
Why is the form being double submitted?
Hello to all! For some reason, at the first click on the Submit form, $.post is sent twice.
Yii2 form code in modal window:
<?php
Modal::begin([
'header' => '<h3>Регистрация организации:</h3>',
'size'=>'modal-lg',
'toggleButton' => [
'label' => 'Регистрация организации',
'tag' => 'button',
'class' => 'btn btn-default',
],
]);
$model=new \common\models\Organization();
$form = ActiveForm::begin([
'id'=>'form-org',
]);
echo $form->field($model, 'title')->textInput()->label('Наименование');
{?>
<div class="row">
<div class="col-xs-4"><?=$form->field($model, 'inn')->textInput()->label('ИНН');?></div>
<div class="col-xs-4"><?=$form->field($model, 'ogrn')->textInput()->label('ОГРН');?></div>
<div class="col-xs-4"><?=$form->field($model, 'kpp')->textInput()->label('КПП');?></div>
</div>
<div class="row">
<div class="col-xs-6"><?=$form->field($model, 'telephone')->textInput()->label('Телефон');?></div>
</div>
<div class="row">
<div class="col-xs-12"><?=$form->field($model, 'address')->textarea()->label('Адрес');?></div>
</div>
<div class='modal-footer'><?=\yii\helpers\Html::submitButton('Сохранить',['class'=>'btn btn-default'])?></div>
<?}
ActiveForm::end();
Modal::end();
$("#form-org").submit(function(event){
$.post(
'guide/add-organziation',
$(this).serialize(),
function(msg) { // получен ответ сервера
console.log(msg);
}
);
return false;
});
Answer the question
In order to leave comments, you need to log in
Paste in your code before sending a POST request
event.preventDefault();
$("#form-org").submit(function(event){
event.preventDefault();
$.post(
'guide/add-organziation',
$(this).serialize(),
function(msg) { // получен ответ сервера
console.log(msg);
}
);
return false;
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question