FormHelper select
Not understanding the Concrete 5 API comment on the select function of the Form Helper, I looked into the source:
/**
* Renders a select field. First argument is the name of the field. Second is an associative array of key => display. Second argument is either the value of the field to be selected (and if it's blank we check post) or a misc. array of fields
* @param string $key
* @return $html
*/
public function select($key, $values, $valueOrArray = false, $miscFields = array())
Select builds a SELECT Dopdown with OPTIONS. That much I already understood from the API.
Here's my explanation of the parameters passed in to select:
-
$key: the name of the element to be created.
-
$values: an array of options, stored as $k=>$value. Used like this:
'<option value="' . $k . '" ' . $selected . '>' . $value . '</option>'; -
$valueOrArray: this can either be set to the default value to be selected (use the option value, not the displayed text between the tags) OR it can be an array and is used as the array to populate $miscFields (see explanation there), omitting the default value. A bit unusual perhaps, probably it's a timesaver when you code these forms a lot.
-
$miscFields: An associative array ($k => $value): insert additional keys into the tag (i.e. multiple="multiple"
The fun in using select is, it STORES your settings between sessions. Boy, I should have used it earlier, when hand-coding this for other parts of the project.
Another note on ValidationErrorHelper:
/**
* Returns whether or not this error helper has more than one error registered within it.
* @return bool
*/
public function has() {
return (count($this->error) > 0);
}
As one can read from the source above, the Validation Helper returns whether there are errors (even if it is only one) or there are none!