我使用部分渲染方法
在弹出窗口中创建了一个表单$userComment=new Comments;
$PopupdetailText .= $this->renderPartial('/comments/_form', array('model' => $userComment),TRUE);
但是现在我面临的问题是表单没有验证。但是当我渲染表单时它会起作用 _form
<?php
/* @var $this CommentsController */
/* @var $model Comments */
/* @var $form CActiveForm */
?>
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'comments-form',
'action' => Yii::app()->createUrl('comments/create'),
'enableAjaxValidation' => FALSE,
'enableClientValidation' => true,
'clientOptions' => array('validateOnSubmit' => true,),
'htmlOptions' => array(
'class' => 'form',
)
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,'type'); ?>
<?php
echo $form->dropDownList($model,'type',
array(""=>"Select Type","0"=>"Offer","1"=>"Events"),
array('style' => 'width:220px;','class'=>'form-control','disabled'=>false,)); ?>
<?php echo $form->error($model,'type'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'offereventid'); ?>
<?php echo $form->textField($model,'offereventid',array('style' => 'width:500px;','class'=>'form-control','disabled'=>false,)); ?>
<?php echo $form->error($model,'offereventid'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'name'); ?>
<?php echo $form->textField($model,'name',array('style' => 'width:500px;','class'=>'form-control','disabled'=>false,)); ?>
<?php echo $form->error($model,'name'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'email'); ?>
<?php echo $form->textField($model,'email',array('style' => 'width:500px;','class'=>'form-control','disabled'=>false,)); ?>
<?php echo $form->error($model,'email'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'comment'); ?>
<?php echo $form->textArea($model,'comment',array('style' => 'width:500px;','class'=>'form-control','disabled'=>false,)); ?>
<?php echo $form->error($model,'comment'); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton($model->isNewRecord ? 'Create' : 'Save',array('class'=>'btn btn-success','style'=>'color:black')); ?>
</div>
<?php $this->endWidget(); ?>
</div><!-- form -->
任何人都可以告诉我我缺少什么吗?我怎样才能实现验证
答案 0 :(得分:0)
渲染方法为renderAjax。这也将填充默认的yii2活动表单验证代码。
答案 1 :(得分:0)
我找到了解决问题的方法。
$userComment = new Comments;
$PopupdetailText .= $this->renderPartial('//comments/_form', array('model' => $userComment,'id'=>$id),TRUE,TRUE);
$PopupdetailText.='</div>
您需要添加True
感谢您的支持