Yii Radio Buttons

2020-07-11 05:19发布

I am using radio buttons in Yii and no matter what I do I can't get the value of the selected button to post. I am sure its just something simple. I am NOT using radioButtonList because I want each button to exist in its own div with an image above it.

Here is my code from the view...

<?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(); ?>

标签: php yii
2条回答
太酷不给撩
2楼-- · 2020-07-11 06:00

In CHtml::activeRadioButtonList's third parameter (htmlOptions) there is an option called 'template'. You should take a look.

查看更多
我欲成王,谁敢阻挡
3楼-- · 2020-07-11 06: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)); ?>

just add

'uncheckValue'=>null

in htmlOption array

it will work..

查看更多
登录 后发表回答