form_input()

form_input([$data = ''[, $value = ''[, $extra = '']]])

Parameters:
  • $data (array) – Field attributes data
  • $value (string) – Field value
  • $extra (mixed) – Extra attributes to be added to the tag either as an array or a literal string
Returns:

An HTML text input field tag

Return type:

string

Lets you generate a standard text input field. You can minimally pass the field name and value in the first and second parameter:

echo form_input('username', 'johndoe');

Or you can pass an associative array containing any data you wish your form to contain:

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

echo form_input($data);

/*
        Would produce:

        <input type="text" name="username" value="johndoe" id="username" maxlength="100" size="50" style="width:50%"  />
*/

If you would like your form to contain some additional data, like JavaScript, you can pass it as a string in the third parameter:

$js = 'onClick="some_function()"';
echo form_input('username', 'johndoe', $js);

Or you can pass it as an array:

$js = array('onClick' => 'some_function();');
echo form_input('username', 'johndoe', $js);
doc_CodeIgniter
2016-10-15 16:32:19
Comments
Leave a Comment

Please login to continue.