Yii 单选按钮 [英] Yii Radio Buttons

查看:26
本文介绍了Yii 单选按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是我的视图代码...

pageTitle=Yii::app()->name;?><h1>欢迎使用<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>选择您的奖品!</h3><div id="奖品"><div class="奖品"><h3>贝宝</h3><?php echo $form->radioButton($model,'user_prize',array('value'=>1));?>

<div class="奖品"><h3>检查</h3><?php echo $form->radioButton($model,'user_prize',array('value'=>2));?>

<div class="奖品"><h3>AlertPay</h3><?php echo $form->radioButton($model,'user_prize',array('value'=>3));?>

<div class="奖品"><h3>Iphone 4</h3><?php echo $form->radioButton($model,'user_prize',array('value'=>4));?>

<div class="奖品"><h3>iPad 2 </h3><?php echo $form->radioButton($model,'user_prize',array('value'=>5));?>

<div class="奖品"><h3>自定义</h3><?php echo $form->radioButton($model,'user_prize',array('value'=>6));?>

<h3>输入您的电子邮件</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><?php echo $form->errorSummary($model);?>

<div class="行按钮"><?php echo CHtml::submitButton('Submit');?>

结束小部件();?>

解决方案

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'=>null

在 htmlOption 数组中

它会起作用..

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

这篇关于Yii 单选按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
PHP最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆