Text field

From PHP on Trax

Jump to: navigation, search

text_field( string $object_name, string $attribute_name, array $options = array() )

Description

Returns an input tag of the "text" type tailored for accessing a specified attribute on an object assigned to the controller. Additional options on the input tag can be passed as an array with options.

$object_name a string which is the name of the instanciated model object in your controller that you want text_field to access for the "value".

$attribute_name a string which is the name of the column in the database table or object's attribute you want text_field to access for the "value".

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

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:
<?= text_field("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 ?>" />
Personal tools