Yii2.0 modal pop-up box + ajax submission form, yii2.0ajax
For example, we use the modal pop-up box + ajax to submit the form. First, we add data-toggle and data-target to the create button of the index view.
The Code is as follows:
<? Php echo Html: a ('add application requests', ['create'], ['class' => 'btn btn-success ', 'Data-toggle '=> 'modal', 'Data-target' =>' # ajax '])?>
Add the following code to the index view to display the modal pop-up box:
<div class="modal bs-example-modal-lg" id="ajax"> <div class="modal-dialog"> <div class="modal-content width_reset" id="tmpl-modal-output-render"> </div> </div></div>
The modified results are as follows:
Then we can modify the create method in the Controller and change render to renderAjax.
return $this->renderAjax('create', [ 'model' => $model, ]);
To add form verification, we need to modify the _ form in views to add the id.
<? Php $ form = ActiveForm: begin (['options' => ['enablesype '=> 'multipart/form-data'], 'id' => 'Leave-form-self '])?> Point to your models to add the verification rule public function rules () {return [['t _ leave_date ','t _ days','t _ reason ', 't_ nickname', 't_ leave_enddate '], 'required'], [['t _ leave_date', 't_ leave_enddate '], 'safe'], [['t _ days '], 'number'], [['t _ reason'], 'string'], [['type', 'add _ time ', 'uid', 'Update _ time', 'status', 'is _ shen'], 'integer'], [['t_ pickup', 't_ nickname ', 't_ pass'], 'string', 'max '=> 20], [['t _ img', 'reviewer _ user', 'audit _ user'], 'string', 'data' => 255];}
The effect is as follows:
In this way, the ajax submission form is implemented.