6.4. Form Elements

The individual elements describing the input portions of the form are arguably the most important part of the form object. They are stored as an associative array in the Solar_Form::$elements property.

Likewise, each element in the $elements property is itself an array describing that element. The descriptor array keys are:


The name of the element, to be used as the name attribute for the element in the form.


The type of element, corresponding to a view helper. E.g., select would use a formSelect helper, resulting in an <select /> tag. The newForm() is able to pick a reasonable type for the element based on the kind of record property; char and varchar columns get input types, columns that use ValidateInList or ValidateInKeys filters get select types, booleans get checkbox types, and so on.


A short label to be placed in a <label> tag associated with the element.


A longer piece of narrative text describing the element; this could be used as a tooltip, as help text, or something similar.


The current value of the element.


A boolean indicating if the element is required to be non-blank. The newForm() method knows that if a table column is NOT NULL, it should set the element as required.


An array of key-value pairs where the key is the option value, and the value is the option label text. This is used for select and radio types so they know what options to present.


An array of key-value pairs where the key is an XHTML attribute name, and the value is the attribute value.


An array of messages regarding why the element value is invalid (if at all).

6.4.1. Element Names

Each element corresponds to what its key will be in the $_POST array (or, if you are using the GET method, the $_GET array -- generally not recommended but sometimes necessary). The element names mimic an array format, where the primary name matches the singular model name, and the keys match the properties of the model record. However, the names are in fact a flat list of strings; they just *look* like array keys.

For example, given an Acme_Model_Blogs_Record, we will see these element names in the form object returned by the newForm() method.

$form->elements['blog[title]']  = array(...); // $_POST['blog']['title']
$form->elements['blog[body]']   = array(...); // $_POST['blog']['body']
$form->elements['blog[status]'] = array(...); // $_POST['blog']['status']
[Note] Note

The newForm() method automatically leaves out "special" columns (primary, created, updated, inherit, etc.) by default.

These names are also used in the form as the element name.

<input name="blog[title]" ... />
<textarea name="blog[body]">...</textarea>
<select name="blog[status]">...</select>