Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CodeIgniter: input box using HTML5 required attribute

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%" /> 
like image 840
Naresh Avatar asked Feb 05 '26 08:02

Naresh


1 Answers

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); 
like image 117
xdazz Avatar answered Feb 06 '26 22:02

xdazz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!