1

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

3

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);
Sign up to request clarification or add additional context in comments.

Comments

0

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

Comments

0

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

Comments

0

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\"");

2 Comments

Girish, 3rd Parameter must be a BOOLEAN value. TRUE or FALSE. Refer the [source code] (github.com/bcit-ci/CodeIgniter/blob/develop/system/helpers/…). Am assuming that the question is related to CI Version 2.0
sorry, you right, i forgot 3rd parameter for form_input(), and form_select, form_radio() function get element attribute in 4th parameter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.