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

发布于 2024-12-13 19:48:21 字数 1765 浏览 0 评论 0原文

我正在使用 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>

I am in the process of setting up a feedback form for my site using codeigniters form helper.

My form has been created and validation implemented, all works.

My only problem is adding the set_value() function to repopulate the form if an error occurs.

I can't get it to work on my radio inputs, how do you add the set_value() function to a radio type.

Code:

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

谷夏 2024-12-20 19:48:21

set_value 仅适用于输入和文本区域。你需要set_radio

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

set_value only works on inputs and textareas. you need set_radio

set_radio()

Permits you to display radio buttons in the state they were submitted.
This function is identical to the set_checkbox() function above.

<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'); ?> />

From doc page: http://codeigniter.com/user_guide/helpers/form_helper.html

时光礼记 2024-12-20 19:48:21
<?= form_radio('found_by', 'newspaper_advert', $found_by == 'newspaper_advert'); ?>
<?= form_radio('found_by', 'newspaper_advert', $found_by == 'newspaper_advert'); ?>
白色秋天 2024-12-20 19:48:21

试试这个,它对我有用:

性别:

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

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

Try this, It works for me:

Gender:

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

< ?php echo form_radio("gender", "Male", NULL, set_radio('gender', 'Male')); ?>Male
時窥 2024-12-20 19:48:21
<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'); ?> />

太容易了......

<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'); ?> />

it is so easy....

手心的海 2024-12-20 19:48:21
 <?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"; ?>

这是正确的代码吗?

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

It is right code in view ??

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文