clonefish elements
Element class
The form elements are represented in $clonefish->elements
as an array of object references. Each element is an object of the element
class or one of its descendants. To manipulate the elements, you have the following options:
Adding an element
The elements are added through the configuration array passed to the clonefish->addElements() method. The configuration array settings are described under the Input types and the Validation types sections in the manual.
Getting a reference to an element
You can reach an element with the
clonefish->getElementByName() method:
class clonefish { element clonefish->getElementByName( string $name ); }
This method returns an object reference if the element was found, and FALSE
otherwise.
Setting value
class element { boolean element->setValue( mixed $value, boolean $slashes_already_added ); }
Sets the value of an element. The returned value is not the result of any kind of validation, do not use it for such purposes.
Parameters:
value
is not a taken as a reference but as a copy.$slashes_already_added
defines if slashes are already added to the value. If it evaluates to true,stripslashes()
will be used on the value (even recursively if it's an array).
Return values:
TRUE
on success, FALSE
on failure. Failure is less likely: only selectDate->setValue()
returns FALSE
when strftime() wasn't successful for the incoming date/timestamp. The returned value shouldn't be used as some kind of validation flag.
Getting value
class element { mixed element->getValue( boolean $addslashes ); }
and
class select extends element { mixed select->getValueArray( boolean $addslashes ); }
Returns the value of the element.
Parameters:
- If
$addslashes
is set toTRUE
, the returned value will be escaped using the built-in PHPaddslashes()
function (even recursively, if the returned value is an array).
Return values:
It returns the value for a simple field (like an inputText).
element->getValue()
for a multiple select (or selectDynamic, or selectFile) element may return the following:
NULL
for empty arrays- if it's an array with only one array element, it returns that array element as scalar value (not in an array)
- if the array has more than one elements, it returns the array.
This triplet matches the behaviour of HTTP GET/POST and PHP when receiving multiple selects during a form submission.
If you expect arrays for a multiple select in every case above, use select->getValueArray()
. Arrays are often expected when the select is used as the "multiple" (N-part) in an 1-N database relation and the returned values are to be inserted in a table.
Getting type of an element
class element { string element->getType( string $name ); }
Returns the class name of an element.
form validation for developers!
clonefish is a proven, mature form generator class that helps PHP developers to create, validate and process secure, flexible and easy-to-maintain formslearn more