php Yii 单选按钮

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8053983/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 03:51:29  来源:igfitidea点击:

Yii Radio Buttons

phpyii

提问by KyleVan

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.

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

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>

结束小部件();?>

回答by 22francis

<?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

'uncheckValue'=>null

in htmlOption array

在 htmlOption 数组中

it will work..

它会工作..

回答by duplabe

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

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