Yii2.0 modal pop-up box +ajax submit form, yii2.0ajax_php tutorial

Source: Internet
Author: User

Yii2.0 modal pop-up box +ajax submit form, Yii2.0ajax


Title we use modal PopOver +ajax Submit form First we add the Create button for the index view Data-toggle and Data-target.

The code is as follows:

<?php echo html::a (' Add leave order ', [' Create '], [' class ' = ' btn ' btn-success ', ' data-toggle ' = ' modal ', ' data-target ' = > ' #ajax '])?>

In the index view, add the following code to display the Modal popup box:

      

The modified effect is as follows

Then we modify the Create method in the controller and change the render to Renderajax.

   return $this->renderajax (' Create ', [    ' model ' = $model,   ]);    

If you want to add a form validation we need to modify the _form in the views to add the ID

<?php $form = Activeform::begin ([' options '] = [' enctype ' = ' multipart/form-data '], ' id ' and ' = ' Leave-form-self '])?> point to your models on the rules Add Validation 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 ' = ', ' [   ' t_img ', ' Reviewer_ User ', ' audit_user '], ' string ', ' max ' = 255]  

The effect is as follows

This enables the AJAX submission form

http://www.bkjia.com/PHPjc/1133111.html www.bkjia.com true http://www.bkjia.com/PHPjc/1133111.html techarticle Yii2.0 modal popup +ajax submit form, Yii2.0ajax title we use modal popup +ajax submit form First we add the index view's Create button Data-toggle and Data-target. ...

  • 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.