I have something crazy like this in one of my forms:
generated from this code:
<div class="row">
<?php echo $form->labelEx($model,'link'); ?>
<?php echo $form->radioButtonList($model,'link[s]', array(
$form->textField($model,'link[]',array('size'=>60,'maxlength'=>128,'value'=>$model->link)),
$form->dropDownList($model,'link[]', CHtml::listData(Page::model()->findAll(), 'url', 'title')),
), array('labelOptions' => array('style' => 'display: inline;'),)); ?>
<?php echo $form->error($model,'link'); ?>
</div>
And I had to add this line in the controller:
$_POST['MenuItem']['link'] = $_POST['MenuItem']['link'][$_POST['MenuItem']['link']['s']];
So it looks like this:
if(isset($_POST['MenuItem']))
{
$_POST['MenuItem']['link'] = $_POST['MenuItem']['link'][$_POST['MenuItem']['link']['s']];
$model->attributes=$_POST['MenuItem'];
if($model->save())
$this->redirect(array('view','id'=>$model->id));
}
I want to use radio buttons to choose one of 2 ways of input for the ‘link’ field in my model.
If first radio button is checked, the value from the textField should be saved in a database.
And if second radio button is checked, the value from the radioButtonList should be saved in a database.
I also want the first radio button to be checked by default.
Is there any easier way to achieve this?