下面的代码创建了一些单选按钮和html与它们一起使用,它运行良好但是我现在想要将第一个单选按钮设置为默认选择的按钮,我不确定需要添加什么。
<?php
for ($i =0; $i < count($packages); $i++){
echo "<div class='package-outter'>";
echo "Name: ".$packages[$i]['Package']['name']."<br>";
echo "Number of Campaigns (per month): ".$packages[$i]['Package']['quantity']."<br>";
echo "Price: ".$packages[$i]['Package']['price']."<br>";
if ($i == 0){
echo $this->Form->input('package', array(
'type' => 'radio',
'options' => array($packages[$i]['Package']['id'] => $packages[$i]['Package']['name'],),
'class' => 'testClass',
));
}else{
echo $this->Form->input('package', array(
'type' => 'radio',
'options' => array($packages[$i]['Package']['id'] => $packages[$i]['Package']['name'],),
'class' => 'testClass',
'hiddenField' => false, // added for non-first elements
));
}
echo "</div>";
}
?>
答案 0 :(得分:2)
我对CakePHP并不熟悉,但快速Google搜索给了我这个
$options = array(
'standard' => 'Standard',
'pro' => 'Pro'
);
$attributes = array(
'legend' => false,
'value' => $foo
);
echo $this->Form->radio('type', $options, $attributes);
所以你应该添加属性&#39; value&#39;并将其设置为默认选定的收音机
答案 1 :(得分:0)
0dp
答案 2 :(得分:0)
如果你尝试相关的值选项,它应该可以工作。
<?php
echo $this->Form->input('status', array(
'div' => true,
'label' => true,
'type' => 'radio',
'legend' => false,
'required' => false,
'hiddenField'=>false,
'options' => array(
1 => 'High',
2 => 'Medium',
3 => 'Low'
)
'value' => 'Medium'
) ); ?>