Yii2.0 modal pop-up box + ajax submission form, yii2.0ajax _ PHP Tutorial

Source: Internet
Author: User
Yii2.0 modal pop-up box + ajax submit form, yii2.0ajax. Yii2.0 modal pop-up box + ajax submit Form. for example, yii2.0ajax uses modal pop-up box + ajax submit Form. First, we add data-toggle and data-target to the create button of index View. 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:

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.

Http://www.bkjia.com/PHPjc/1133111.htmlwww.bkjia.comtruehttp://www.bkjia.com/PHPjc/1133111.htmlTechArticleYii2.0 mode pop-up box + ajax submit form, yii2.0ajax: In this 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 ....

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.