Yii Framework Forum: ajax form submit - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

ajax form submit ajax form submit

#1 User is offline   olegstan 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 05-December 14

Posted 05 December 2014 - 10:26 AM

I have ajax form submit.
If I submit, script send ajax request, but user stay on this page and maybe he want to edit this form again.
Second submit not send ajax request, I don't know why.


I have this code

<?php $form = ActiveForm::begin([
'id' => 'form-user-setting',
'options' => [
'class' => 'form-horizontal',
],
'enableAjaxValidation' => true,
'enableClientValidation' => true,
'validateOnChange' => false,
'validationDelay' => false,
'validateOnBlur' => false,
'validateOnType' => false,
'validateOnSubmit'=>true,
'validationUrl' => ['/user/update-ajax-user'],
'requiredCssClass' => '',
]); ?>
<h4 class="mb-xlg">Пользовательские настройки</h4>
<fieldset>
<div class="form-group">
<div class="col-md-8 col-md-offset-3">
<div id="form-user-setting-flash-success" class="form-control alert-success" style="display: none">Настройки профиля успешно изменеы</div>
</div>
</div>
<div class="form-group">
<div class="col-md-8 col-md-offset-3">
<div id="form-user-setting-flash-error" class="form-control alert-danger" style="display: none">Форма заполнена неправильно</div>
</div>
</div>

<?= $form->field($user->userSetting, 'nickname', ['template' => '{label}<div class="col-md-8">{input}</div>', 'labelOptions' => ['class' => 'col-md-3 control-label']])->textInput() ?>
<?= $form->field($user->userSetting, 'show_nickname', ['checkboxTemplate' => '{label}<div class="col-md-8"><div class="checkbox-custom checkbox-default checkbox-inline mt-xs">{input}<label></label></div></div>', 'labelOptions' => ['class' => 'col-xs-3 control-label mt-xs pt-none'] , 'options' => ['class' => 'form-group']])->label()->checkBox(['value' => 1]) ?>
<?= $form->field($user->userSetting, 'show_panel', ['checkboxTemplate' => '{label}<div class="col-md-8"><div class="checkbox-custom checkbox-default checkbox-inline mt-xs">{input}<label></label></div></div>', 'labelOptions' => ['class' => 'col-xs-3 control-label mt-xs pt-none'] , 'options' => ['class' => 'form-group']])->label()->checkBox(['value' => 1]) ?>
<?= $form->field($user->userSetting, 'about', ['template' => '{label}<div class="col-md-8">{input}{error}</div>', 'labelOptions' => ['class' => 'col-md-3 control-label']])->textarea() ?>
<?= $form->field($user->userSetting, 'specialty', ['template' => '{label}<div class="col-md-8">{input}</div>', 'labelOptions' => ['class' => 'col-md-3 control-label']])->textInput() ?>
<div class="row">
<div class="col-md-9 col-md-offset-3">
<?= Html::submitButton('Изменить', ['class' => 'btn btn-primary', 'name' => 'signup-button']) ?>
</div>
</div>
</fieldset>
<script>
$(document).ready(function() {
$('#form-user-setting').on('submit', function(e){
console.log(1);

e.preventDefault();
}).on('afterValidate', function (e, messages, deferred, attribute) {

e.preventDefault();

var isSuccess = true;
$.each(messages, function(k, v){
if(!$.isEmptyObject(v)){
isSuccess = false;
}
});

if(isSuccess){
$("#form-user-setting-flash-success").show().fadeIn(100).fadeOut(5000);
}else{
$("#form-user-setting-flash-error").show().fadeIn(100).fadeOut(5000);
}

});
});
</script>
<?php ActiveForm::end(); ?>
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users