[英]How to add required attribute to html5 form radio input using codeigniter
I want to produce a radio button like this: 我想制作一个这样的单选按钮:
<input type="radio" name="quest0" value="a" required>
I am doing like this 我这样做
echo form_radio("quest0","a");
But how can I add required
attribute using Codeigniter form helper. 但是如何使用Codeigniter表单助手添加
required
属性。
I think you can do it this way.(I did not tested it) 我想你可以这样做。(我没有测试过)
$data = array(
'name' => 'quest0',
'value' => 'a',
'required' => 'required'
);
echo form_radio($data);
Try this: 尝试这个:
<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'); ?> />
您可以添加其他属性,如id
, data-*
, required
在第四个参数form_radio()
函数,试试这个代码
echo form_radio("quest0","a", false,"required id=\"quest0\"");
One way is to write as shown by @Shaiful Islam. 一种方法是写@Shaiful Islam所示。
Other way is to write as below: 其他方法是写如下:
echo form_radio("quest0","a", FALSE, "required=required");
Refer the Source Code - Form Helper - Line 459 请参阅源代码 - 表格助手 - 第459行
You are passing the other parameters as EXTRA attribute 您将其他参数作为EXTRA属性传递
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.