php codeigniter -表单助手-如何在无线电输入上实现set_value

js5cn81o  于 2022-12-07  发布在  PHP
关注(0)|答案(5)|浏览(134)

我正在使用codeigniters表单助手为我的站点设置一个反馈表单。
我的表单已创建并实施了验证,一切正常。
我唯一的问题是添加set_value()函数,以便在发生错误时重新填充表单。
我不能让它在我的无线电输入上工作,你怎么把set_value()函数添加到一个无线电类型。
编码:

<ul> 
          <li><?php echo form_radio('found_by', 'newspaper_advert', set_value('found_by')); ?> Newspaper advert</li>
          <li><?php echo form_radio('found_by', 'press_release', set_value('found_by')); ?> Press release</li>
          <li><?php echo form_radio('found_by', 'text_message', set_value('found_by')); ?> Text message</li>
          <li><?php echo form_radio('found_by', 'email', set_value('found_by')); ?> Email</li>
          <li><?php echo form_radio('found_by', 'refferal', set_value('found_by')); ?> Referred to by a friend</li>
          <li><?php echo form_radio('found_by', 'telemarketing', set_value('found_by')); ?> Telemarketing</li>
          <li><?php echo form_radio('found_by', 'leaflet_flyer', set_value('found_by')); ?> Leaflet or flyer</li>
          <li><?php echo form_radio('found_by', 'radio', set_value('found_by')); ?> Radio</li>
          <li><?php echo form_radio('found_by', 'television', set_value('found_by')); ?> Television</li>
          <li><?php echo form_radio('found_by', 'internet_advert', set_value('found_by')); ?> Internet advert</li>
          <li><?php echo form_radio('found_by', 'search_engine', set_value('found_by')); ?> Search engine</li>
          <li><?php echo form_radio('found_by', 'none', set_value('found_by')); ?> None of the above</li>
      </ul>
uyhoqukh

uyhoqukh1#

set_value只对输入和文本区域起作用.你需要set_radio

设置无线电()

允许您以提交状态显示单选按钮。此函数与上面的set_checkbox()函数相同。

<input type="radio" name="myradio" value="1" <?php echo set_radio('myradio', '1', TRUE); ?> />
<input type="radio" name="myradio" value="2" <?php echo set_radio('myradio', '2'); ?> />

从文档页:http://codeigniter.com/user_guide/helpers/form_helper.html

wfauudbj

wfauudbj2#

<?= form_radio('found_by', 'newspaper_advert', $found_by == 'newspaper_advert'); ?>
dwthyt8l

dwthyt8l3#

试试这个,它对我很有效:

性别:

< ?php echo form_radio("gender", "Female", NULL, set_radio('gender', 'Female')); ?>Female

< ?php echo form_radio("gender", "Male", NULL, set_radio('gender', 'Male')); ?>Male
jvidinwx

jvidinwx4#

<input type="radio" name="myradio" value="1" <?php echo  set_radio('myradio', '1'); ?> />
<input type="radio" name="myradio" value="2" <?php echo  set_radio('myradio', '2'); ?> />
<input type="radio" name="myradio" value="3" <?php echo  set_radio('myradio', '3'); ?> />
<input type="radio" name="myradio" value="4" <?php echo  set_radio('myradio', '4'); ?> />

它是如此容易....

n3h0vuf2

n3h0vuf25#

<?php echo form_radio( array( 'name'=> 'age_group','id'=>'age_group','class'=> 'input-xsmall focused inputError','type'=>'radio',set_radio('age_group', 'under 18', TRUE) ) ). "under 18"; ?><br />
            <?php echo form_radio( array( 'name'=> 'age_group','id'=>'age_group','class'=> 'input-xsmall focused inputError','type'=>'radio',set_radio('age_group', '18 to 29', TRUE) ) ). "18 to 29"; ?><br />
            <?php echo form_radio( array( 'name'=> 'age_group','id'=>'age_group','class'=> 'input-xsmall focused inputError','type'=>'radio',set_radio('age_group', '30 to 49', TRUE) ) ). "30 to 49"; ?><br />
            <?php echo form_radio( array( 'name'=> 'age_group','id'=>'age_group','class'=> 'input-xsmall focused inputError','type'=>'radio',set_radio('age_group', 'above 49', TRUE) ) ). "above 49"; ?>

查看的代码是否正确??

相关问题