I have two models say A and B rendering in one form, when i submit the form request going to A controller and validating all A mandatory fields but not B.
My A model is below i am posting only rules.
class Bugs extends CActiveRecord
{
public function rules()
{
return array(
array('assigned_to, short_desc', 'required'),
array('assigned_to', 'numerical', 'integerOnly'=>true),
);
}
}
My B model is below
class BugsFulltext extends CActiveRecord
{
public function rules()
{
return array(
array('bug_id, short_desc, comments', 'required'),
array('bug_id', 'numerical', 'integerOnly'=>true),
array('short_desc', 'length', 'max'=>255),
array('comments_noprivate', 'safe'),
array('bug_id, short_desc, comments, comments_noprivate', 'safe', 'on'=>'search'),
);
}
}
and my A controller ie. BugsController goes below
class BugsController extends Controller
{
public function actionCreate()
{
$model=new Bugs;
$problemdescription=new BugsFulltext;
if(isset($_POST['Bugs'],$_POST['BugsFulltext']))
{
$model->attributes=$_POST['Bugs'];
$problemdescription->attributes=$_POST['BugsFulltext'];
if($model->save())
$this->redirect(array('view','id'=>$model->bug_id));
}
$this->render('create',array(
'model'=>$model,
'problemdescription'=>$problemdescription,
));
}
}
and my form is here
<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'bugs-form',
'enableAjaxValidation'=>false,
'enableClientValidation'=>true,
));
?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model);echo $form->errorSummary($problemdescription); ?>
<div class="row">
<?php echo $form->labelEx($model,'assigned_to'); ?>
<?php echo $form->textField($model,'assigned_to'); ?>
<?php echo $form->error($model,'assigned_to'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,'short_desc'); ?>
<?php echo $form->textField($model,'short_desc',array('size'=>60,'maxlength'=>255)); ?>
<?php echo $form->error($model,'short_desc'); ?>
</div>
<div class="row">
<?php echo $form->labelEx($problemdescription,'comments'); ?>
<?php echo $form->textArea($problemdescription,'comments',array('rows'=>4, 'cols'=>45)); ?>
<?php echo $form->error($problemdescription,'comments'); ?>
</div>
I am using yii 1.1.7 i enabled client side validation, my textarea field ‘comments’ is validating on client if it is empty, but when i submit the page, on the controller actionID even though it is empty its not giving error message while for the remaining two fields its throwing error on empty.
Could some one help me on this.
Thanks in advance,
Pavan