Understanding Form Elements
Omeka makes heavy use of Zend’s Form_Element class for building forms, rather than writing out the HTML explicitly.
Typically, elements are added directly to an Omeka_Form
object or an Omeka_Form_Admin
object.
The basic structure is to use the addElement()
method, with three parameters:
string
$elementA string name for the form element. Typical examples are: button, captcha, checkbox, file, multicheckbox, multiselect, radio, select, submit, text, textarea.
An element object can also be passed in here. In this (rare) case, the other two parameters are usually unnecessary
string
$nameThe name attribute for the form element
array
$optionsAdditional options for the form element.
label
,description
, andrequired
are the most common options. HTML attributes such asrows
andcols
can also appear here, as well asclass
In more complex examples, an array of
validators
can also be passed here
Examples
$form->addElement('textarea', 'description', array(
'label' => __('Description'),
'description' => __('My record description'),
'rows' => 10
));
$form->addElement('text', 'user_email', array(
'label' => __('Email'),
'description' => __("Preferred email address of the person submitting the record"),
'validators' => array('EmailAddress'),
'required' => true
));
For a more extended example, see the IndexController::_getForm() method in the SimplePages plugin, bundled with Omeka.