2015-08-09 95 views
0

我的AJAX信息非常少。這就是爲什麼我在這裏問我的問題...Yii2 ajax驗證並提交表格

in yii2如何創建和提交表單與Ajax驗證?

所以我搜查,但沒有找到合適的解決方案...

例如:(根據官方培訓現場)

<?php $form = ActiveForm::begin([ 
      'id' => $model->formName(), 
      'enableAjaxValidation' => true, 
]); ?> 


<?= $form->field($model, 'title')->textInput(['maxlength' => true]) ?> 

<?= $form->field($model, 'extra_txt')->textInput(['maxlength' => true]) ?> 

<div class="form-group"> 
    <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => $model->isNewRecord ? 'btn btn-success' : 'btn btn-primary']) ?> 
</div> 

<?php ActiveForm::end(); ?> 

和控制器:

if (Yii::$app->request->isAjax && $model->load(Yii::$app->request->post())) { 
     Yii::$app->response->format = 'json'; 
     return ActiveForm::validate($model); 
    } else { 
     return $this->render('create', [ 
      'model' => $model, 
     ]); 
    } 

我的問題:

1- ajax驗證

2-使用ajax提交表格

回答