Helpers::FormTagHelper::text_field_tag

text_field_tag( string $name, string $value = null, array $options = array() )


Description

Creates a standard text field.

$name a string which is the name of the text field (name="$name").

$value a string which is the value of the text field (value="value").


$options is an array of key => value pairs of options for the input tag.

  • "disabled" - If set to true, the user will not be able to use this input.
  • "size" - The number of visible characters that will fit in the input.
  • "maxlength" - The maximum number of characters that the browser will allow the user to enter.

Returns an input type="text" tag converting the $options into html options on the tag.


Examples

Code:
<?= text_field("person", "name", array("size" => 25)) ?>
Output:
<input type="text" id="person_name" name="person[name]" size="25" value="<?= $person->name?>" />

If the object name contains square brackets the id for the object will be inserted.
Code:
<?= textfield "person[]", "name" ?>
Output:
<input type="text" id="person_<?= $person->id ?>_name" name="person[<?= $person->id ?>][name]" value="<?= $person->name ?>" />

Code:
<?= text_field("person", "name", array("index" => 5)) ?>
Output:
<input type="text" id="person_5_name" name="person[5][name]" value="<?= $person->name ?>" />