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:
-
name
-
The name of the element, to be used as the name attribute for the element in the form.
-
type
-
The type of element, corresponding to a view helper. E.g.,
select
would use aformSelect
helper, resulting in an<select />
tag. ThenewForm()
is able to pick a reasonable type for the element based on the kind of record property; char and varchar columns getinput
types, columns that useValidateInList
orValidateInKeys
filters getselect
types, booleans getcheckbox
types, and so on. -
label
-
A short label to be placed in a <label> tag associated with the element.
-
descr
-
A longer piece of narrative text describing the element; this could be used as a tooltip, as help text, or something similar.
-
value
-
The current value of the element.
-
require
-
A boolean indicating if the element is required to be non-blank. The
newForm()
method knows that if a table column isNOT NULL
, it should set the element as required. -
options
-
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.
-
attribs
-
An array of key-value pairs where the key is an XHTML attribute name, and the value is the attribute value.
-
invalid
-
An array of messages regarding why the element value is invalid (if at all).
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.
<?php
$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 | |
---|---|
The |
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>