【发布时间】:2014-05-12 02:43:34
【问题描述】:
在用于编辑详细信息的表单中,我有一个带有值 0 和 1 的单选按钮。我想要的是,当表单被加载时,即当用户点击edit 链接时,单选按钮应该设置为数据库中的值。一旦用户更改并提交表单,它应该保留提交的值。这怎么可能?
我尝试了以下代码,但没有成功。我知道不能这样。 $row->videotype 具有数据库中的值。
<input type="radio" name="trailer" value="1" <?php
if(set_radio('trailer', '1', TRUE)) {
echo set_radio('trailer', '1', TRUE);
} else {
if($row->videotype==1) ?> checked=checked <?php
} ?> />Yes
<input type="radio" name="trailer" value="0" <?php
if(set_radio('trailer', '0')) {
echo set_radio('trailer', '0');
} else {
if($row->videotype==0) ?> checked=checked <?php
} ?> />No
在表单提交功能中(在控制器中),我已将其设置为表单验证:
$this->form_validation->set_rules('trailer', 'Trailer', 'is_numeric');
谁能帮我解决这个问题?提前致谢。
【问题讨论】:
标签: php codeigniter radio-button