I am doing like this echo form_radio("quest0","a"); " /> I am doing like this echo form_radio("quest0","a"); " /> I am doing like this echo form_radio("quest0","a"); "/>

How to add required attribute to html5 form radio input using codeigniter

717 views Asked by At

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.

4

There are 4 answers

0
Shaiful Islam On

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);
0
Bharat Kr. Lal On

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

You can add other attributes like id, data-*, required in 4th parameter of form_radio() function, try this code

echo form_radio("quest0","a", false,"required id=\"quest0\"");
0
Vinod Tigadi On

One way is to write as shown by @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
You are passing the other parameters as EXTRA attribute