Question

I want to create dropdownbox in Yii framework which have name is Category,I copy in the stackoverflow but it has error,

<form>
    <?php   
       $list = CHtml::listData(Categories::model()->findAll(array('order' => 'cate_name')), 'id', 'cate_name');
       echo $form->dropDownList("Category", 'cate_name', $list);
    ?>
</form>

here is error:

Undefined variable: form

Was it helpful?

Solution

Your form should looks like this:

<?php $form=$this->beginWidget('CActiveForm', array(
    'id'=>'your-form',
    'enableAjaxValidation'=>false,
)); ?>
<?php   
    $list = CHtml::listData(Categories::model()->findAll(array('order' => 'cate_name')), 'id', 'cate_name');
    echo $form->dropDownList("Category", 'cate_name', $list);
?>
<?php $this->endWidget(); ?>

NOTE: replace form tag with form widget

OTHER TIPS

Instead of using html form tag, you have to use yii form widget.

<?php $form=$this->beginWidget('CActiveForm', array(
        'id'=>'form_id',        
)); ?>

For tutorial: http://www.yiiframework.com/doc/guide/1.1/en/form.view

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top