Zend\Form\Element is a base class for all specialized elements and Zend\Form\Fieldset, but can also be used for all generic text, select, radio, etc. type form inputs which do not have a specialized element available.
Basic Usage of Zend\Form\Element
At the bare minimum, each element or fieldset requires a name. You will also typically provide some attributes to hint to the view layer how it might render the item.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | use Zend\Form\Element;
use Zend\Form\Form;
$username = new Element('username');
$username
->setLabel('Username');
->setAttributes(array(
'type' => 'text',
'class' => 'username',
'size' => '30',
));
$password = new Element('password');
$password
->setLabel('Password');
->setAttributes(array(
'type' => 'password',
'size' => '30',
));
$form = new Form('my-form');
$form
->add($username)
->add($password);
|
setName(string $name)
Set the name for this element.
Returns Zend\Form\Element
getName()
Return the name for this element.
Returns string
setLabel(string $label)
Set the label content for this element.
Returns Zend\Form\Element
getLabel()
Return the label content for this element.
Returns string
setLabelAttributes(array $labelAttributes)
Set the attributes to use with the label.
Returns Zend\Form\Element
getLabelAttributes()
Return the attributes to use with the label.
Returns array
setOptions(array $options)
Set options for an element. Accepted options are: "label" and "label_attributes", which call setLabel and setLabelAttributes, respectively.
Returns Zend\Form\Element
setAttribute(string $key, mixed $value)
Set a single element attribute.
Returns Zend\Form\Element
getAttribute(string $key)
Retrieve a single element attribute.
Returns mixed
hasAttribute(string $key)
Check if a specific attribute exists for this element.
Returns boolean
setAttributes(array|Traversable $arrayOrTraversable)
Set many attributes at once. Implementation will decide if this will overwrite or merge.
Returns Zend\Form\Element
getAttributes()
Retrieve all attributes at once.
Returns array|Traversable
clearAttributes()
Clear all attributes for this element.
Returns Zend\Form\Element
setMessages(array|Traversable $messages)
Set a list of messages to report when validation fails.
Returns Zend\Form\Element
getMessages()
Returns a list of validation failure messages, if any.
Returns array|Traversable
The source code of this file is hosted on GitHub. Everyone can update and fix errors in this document with few clicks - no downloads needed.