Yii电台按钮

时间:2011-11-08 16:44:20

标签: php yii

我在Yii中使用单选按钮,无论我做什么,我都无法获得所选按钮的值。我确信它只是简单的事情。我不使用radioButtonList,因为我希望每个按钮都存在于自己的div中,上面有一个图像。

以下是我在视图中的代码......

<?php $this->pageTitle=Yii::app()->name; ?>

<h1>Welcome to <i><?php echo CHtml::encode(Yii::app()->name); ?></i></h1>

<div class="form">
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'lead_form',
'enableAjaxValidation'=>false,
)); ?>
<h3>Choose Your Prize!</h3>

 <div id="prizes">
<div class="prize">
<h3>Paypal</h3>
<?php echo $form->radioButton($model,'user_prize',array('value'=>1)); ?>
</div>
<div class="prize">
<h3>Check</h3>
<?php echo $form->radioButton($model,'user_prize',array('value'=>2)); ?>
</div>
<div class="prize">
<h3>AlertPay</h3>
<?php echo $form->radioButton($model,'user_prize',array('value'=>3)); ?>
</div>
<div class="prize">
<h3>Iphone 4</h3>
<?php echo $form->radioButton($model,'user_prize',array('value'=>4)); ?>
</div>
<div class="prize">
<h3>Ipad 2</h3>
<?php echo $form->radioButton($model,'user_prize',array('value'=>5)); ?>
</div>
<div class="prize">
<h3>Custom</h3>
<?php echo $form->radioButton($model,'user_prize',array('value'=>6)); ?>
</div>
</div>
<h3>Enter Your Email</h3>
<div id="mainemail">
<div class="row">
    <?php echo $form->labelEx($model,'user_email'); ?>
    <?php echo $form->textField($model,'user_emhttp://stackoverflow.com/editing-    helpail'); ?>
    <?php echo $form->error($model,'user_email'); ?>
</div>

<div>
    <?php echo $form->errorSummary($model); ?>
</div>

<div class="row buttons">
    <?php echo CHtml::submitButton('Submit'); ?>
</div>

endWidget(); ?&GT;

2 个答案:

答案 0 :(得分:12)

<?php echo $form->radioButton($model,'user_prize',array('value'=>1,'uncheckValue'=>null)); ?>
<?php echo $form->radioButton($model,'user_prize',array('value'=>2,'uncheckValue'=>null)); ?>
<?php echo $form->radioButton($model,'user_prize',array('value'=>3,'uncheckValue'=>null)); ?>
<?php echo $form->radioButton($model,'user_prize',array('value'=>4,'uncheckValue'=>null)); ?>
<?php echo $form->radioButton($model,'user_prize',array('value'=>5,'uncheckValue'=>null)); ?>

只需添加

  

'uncheckValue'=&GT;空

在htmlOption数组中

它会起作用..

答案 1 :(得分:1)

在CHtml :: activeRadioButtonList的第三个参数(htmlOptions)中有一个名为'template'的选项。你应该看看。