Tilak Tilak - 2 months ago 12
PHP Question

Required Field but its allowing empty in yii

I have problem with yii-CJuiAutoComplete. required field is not working for only one field. added required rule in the model.but its not working. its my _form.php

<div class="form-group">
<?php echo $form->labelEx($model,'collegename',array('class'=>'col-sm-3 control-label')); ?>

<div class="col-sm-9">
<?php
$this->widget('zii.widgets.jui.CJuiAutoComplete', array(
'model'=>$form,
'name'=>'collegename',
'source'=>$this->createUrl('controller/action'),
// additional javascript options for the autocomplete plugin
'options'=>array(
'showAnim'=>'fold',

),
'htmlOptions'=>array(
// 'style'=>'height:20px;',
'class'=>'span5 form-control',
'placeholder'=>'College Name',
//'style' => 'text-transform: uppercase'
),
));
?>
<?php echo $form->error($model,'collegename'); ?>
</div>
</div>


model

array('collegename', 'required'),

Answer

You pass the form instead of the model. Try:

<?php 
 $this->widget('zii.widgets.jui.CJuiAutoComplete', array(

   'model'=>$model,

   'attribute'=>'collegename',

   'source'=>$this->createUrl('controller/action'),
   // additional javascript options for the autocomplete plugin
   'options'=>array(
       'showAnim'=>'fold',

   ),
   'htmlOptions'=>array(
      // 'style'=>'height:20px;',
       'class'=>'span5 form-control',
       'placeholder'=>'College Name',
       //'style' => 'text-transform: uppercase'
   ),
 )); 
 ?>
Comments