Yii2.0 modal pop-up box ajax submission form, yii2.0ajax_PHP tutorial

WBOY
Release: 2016-07-12 08:50:36
Original
1098 people have browsed it

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

As the title says, we use modal pop-up box ajax to submit the form. First, we add data- to the create button of the index view. toggle and data-target.

The code is as follows:

<&#63;php 
echo Html::a('添加请假单', ['create'], ['class' => 'btn btn-success','data-toggle'=>'modal','data-target'=>'#ajax']) 
&#63;>
Copy after login

Add the following code in 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>

Copy after login

The modified effect is as follows

Then we modify the create method in the controller and change render to renderAjax

   return $this->renderAjax('create', [
    'model' => $model,
   ]); 
   
Copy after login

If you want to add form validation, we need to modify _form in views and add the id

<&#63;php $form = ActiveForm::begin(['options' => ['enctype' => 'multipart/form-data'],'id'=>'leave-form-self']) &#63;>
指向 你的models 在rules添加上验证规则

 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', 'max' => 255]
  ];
 } 

Copy after login

The effect is as follows

This implements the ajax submission form

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1133111.htmlTechArticleYii2.0 modal pop-up box ajax submission form, yii2.0ajax As the title says, we use modal pop-up box ajax submission form First, we add data-toggle and data-target to the create button of the index view. ...
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!