yii save dropdown checked state on page refresh

2019-09-16 19:18发布

问题:

In yii save a dropdown checked state of "yes" when the page reloads, if that is chosen? It defaults to "No".. Thanks!!

getAttributeLabel('MULTI_PART_FORM')); ?>

       <td class="type-text"><?php echo CHtml::dropDownList('MULTI_PART_PO','',array( 0=>'No',1=>'Yes'), array('onChange' => "$('#MULTI_PART_VIEW').show();")); ?></td>  
    </tr>
    <tr id="MULTI_PART_VIEW" style="display:none">
        <th><?php echo CHtml::encode($model->getAttributeLabel('MULTI_PART_VIEW')); ?></th>
        <td><?php echo CHtml::activeTextField($model,'MULTI_PART_PO',array('size'=>120,'maxlength'=>64,'value'=>$model->MULTI_PART_PO)); ?></td>
            <?php

回答1:

//VIEW CODE
echo CHtml::beginForm(Yii::app()->createUrl("{controllername}/save",array(/*'{controller parameter}'=>{parameter value},*/)),'post',array('id'=>'form_id'));

    echo CHtml::dropDownList('MULTI_PART_PO',$saved_dropdown_value,array( 0=>'No',1=>'Yes'), array('onChange' => "$('#MULTI_PART_VIEW').show();"));
    //dropDownList(string $name, string $select="the selected value", array $data, array $htmlOptions=array ( ))

echo CHtml::endForm();


//CONTROLLER CODE (add function Save to accessRules array)
public function actionSave(/*{controller parameter}*/)
{
    $model=new {Modelname};

    if(isset($_POST["MULTI_PART_PO"]))
    {
        $model->multi_part_po = $_POST["MULTI_PART_PO"];
        $model->save();
    }

    $this->render('{Viewname}',array(
        'saved_dropdown_value'=>$model->multi_part_po,
    ));
}