This article mainly introduces the implementation ideas and related code of Yii2.0 modal pop-up box + ajax form submission, which is very simple and practical, if you have any need, refer to the following 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:
'Btn btn-success ', 'data-toggle' => 'modal', 'data-target' => '# ajax'])?>
Add the following code to the index View to display the modal pop-up box:
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.
['Enabledype '=> '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.
For more information about the Yii2.0 modal pop-up box and ajax submission form, see PHP!