YII 2模态中的表格验证

时间:2017-05-13 07:13:05

标签: javascript php jquery yii2 yii2-basic-app

在我的视图页面中,我有2个模态,在同一模型中有2个活动形式,

我正在使用yii \ bootstrap \ ActiveForm;在我的视图页面中,

我的第一个模态:

<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" data-backdrop="static" data-keyboard="false" aria-labelledby="myLargeModalLabel" id="dialog1" style="display:none;" aria-hidden="true">
  <div class="modal-dialog modal-lg" >
        <div class="modal-content">
            <div class="modal-header">

                <h4 class="modal-title">List Box Details</h4>
            </div>
            <div class="modal-body" style="height:420px;">
                  <div class="portlet-body form">
                <!-- BEGIN FORM-->
                <?php

  $form = ActiveForm::begin(['enableClientValidation'=>true,         
                         'validateOnSubmit'=>true,
                        ]); ?>

    <div class="form-body">

     <div class="form-group" style="padding-left: 50px;">
                             <?php  echo $form->field($model,'c_id')->hiddenInput(['id'=>'c_id','value'=>$id])->label(false);  ?>
                             <?php echo $form->field($model,'c_component_type')->hiddenInput(['id'=>'c_component_type','value'=>'2'])->label(false); ?>

                            <div class="col-sm-10" align="center">
                                <?php 

                                    $cmps_names = ArrayHelper::map(Group::find()->where(['and','c_status = "1"'])->all(), 'c_group_id', 'c_group_name');

                                          //  $cmps_names = ArrayHelper::map($data, 'c_group_id', 'c_group_name');

                      echo $form->field($model,'c_component_role' ,['template'=>"<div class=\"form-group form-md-line-input\">{input}
                            {beginLabel}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n <div class=\"form-control-focus\">\n</div>\n</div>"])->dropDownList($cmps_names, ['prompt'=>'Select group ','style' => 'color:black']) ?>

                            </div>
                        </div>   

                           <div style="height:15px;"></div>   


                         <div class="form-group" style="padding-left: 50px;">
                         <div class='row'>

                            <div class="col-sm-10" align="center">
                               <?php 
                                  echo  $form->field($model, 'c_label', ['template'=>"<div class=\"form-group form-md-line-input has-success form-md-floating-label\">\n<div class=\"input-icon right\">\n{input}
                                    {beginLabel}\n{labelTitle}\n{endLabel}\n{hint}\n<i class=\"icon-user\"></i>\n</div>\n</div>\n{error}"],['options'=>['class'=>'form-control form-control-inline labl','data-comp_id'=>'2']])->textInput(['style' => 'color:black']) ?>
                               <span class="label_status" style="color:red;font-style:italic;"></span>
                            </div>
                            <div class="col-sm-2"></div>
                            </div>
                            </div>

                              <div style="height:15px;"></div>    

                         <div class="row" >
                          <div class="col-sm-1"></div>
                            <div class="col-sm-4" align="left">
                                <?php 

                                 $cmps_names = ArrayHelper::map(Master::find()->where(['and','c_status = "1"'])->all(), 'c_master_id', 'c_master_name');


                                   echo $form->field($model,'c_list_model' ,['template'=>"<div class=\"form-group form-md-line-input\">{input}
                            {beginLabel}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n <div class=\"form-control-focus\">\n</div>\n</div>"])->dropDownList($cmps_names, ['prompt'=>'Select group ','style' => 'color:black']) ?>

                            </div>
                         <div class="col-sm-1"></div>
                            <div class="col-sm-4" id="list_column" align="left">
                                <?php 


                                if($model->c_list_column == "" && $model->c_list_model == ""){

                                  $list_model="";
                                  $list_column="";

                                     $select[''] = '-- Please Select --';
                                echo $form->field($model,'c_list_column' ,['template'=>"<div class=\"form-group form-md-line-input\">{input}
                            {beginLabel}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n <div class=\"form-control-focus\">\n</div>\n</div>"])->dropDownList($select, ['prompt'=>'Select group ','style' => 'color:black']) ?>

                               <?php }else { 

                                $list_model = $model->c_list_model;
                                $list_column = $model->c_list_column;

                                     $select[''] = '-- Please Select --';
             echo $form->field($model,'c_list_column' ,['template'=>"<div class=\"form-group form-md-line-input\">{input}
                            {beginLabel}\n{labelTitle}\n{endLabel}\n{error}\n{hint}\n <div class=\"form-control-focus\">\n</div>\n</div>"])->dropDownList($select, ['prompt'=>'Select group ','style' => 'color:black']) ?>
                             <?php    }?>



                            </div>
                            </div>




    </div>

        <div class="row">
            <div class="col-md-12">
                <div class="col-md-offset-5 col-md-9">
                    <?= Html::submitButton($model->isNewRecord ? 'Create' : 'Update', ['class' => 'btn purple mt-ladda-btn ladda-button btn-circle' ,'id'=>'btnSubmit1']) ?>
                </div>
            </div>
        </div>


 <?php ActiveForm::end(); ?>
            </div>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn red-intense"  data-dismiss="modal">Close</button>
            </div>
        </div>
        <!-- /.modal-content -->
    </div>
    <!-- /.modal-dialog -->
</div>

我的第二个模态具有相同的组件,但在该模态活动字段中,隐藏的字段数据值已更改。

我需要对这两种表格进行单独验证。

注意:

我有单身模特, 在单个创建页面中, 在创建页面中,

我的错误:

当我提交表单时,它在模态中不显示错误, 它会自动重新加载页面并关闭模态。

我的要求:

单击没有页面刷新和模态关闭功能的模态提交按钮时,我需要一条错误消息。如果验证中没有错误,它应该加载页面并将数据保存在数据库中。

0 个答案:

没有答案