3

I have a form in the CodeIgniter framework, and I want to use the HTML "required" attribute. How can I do that?

$data = array(
              'name'        => 'username',
              'id'          => 'username',
              'value'       => 'johndoe',
              'maxlength'   => '100',
              'size'        => '50',
              'style'       => 'width:50%',
            );

echo form_input($data); 

The result needed:

    <input type="text" name="username" id="username" value="johndoe" 
required maxlength="100" size="50" style="width:50%" /> 
3
  • 4
    Not really familiar with codeigniter but can't you just do 'required' => 'required'? Commented May 19, 2013 at 12:45
  • please make it ans.. i need to give you +1 Commented May 19, 2013 at 12:49
  • 2
    Looks like somebody has already posted it, no point duplicating the answer :p Commented May 19, 2013 at 12:51

1 Answer 1

7

You just need to add it to the array.

$data = array(
              'name'        => 'username',
              'id'          => 'username',
              'value'       => 'johndoe',
              'maxlength'   => '100',
              'size'        => '50',
              'style'       => 'width:50%',
              'required' => 'required'
 );

echo form_input($data); 
Sign up to request clarification or add additional context in comments.

2 Comments

thaanx.. it solved .. but in past or present i doesn't read " required=required ". i always read " required ". So i asked question.
You can use empty string as a value for required attribute (as per) as well.

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.