Methods summary
public static
|
#
loadConfig( string|array $file, array $options = array() )
Factory method to load form fields from config.
Factory method to load form fields from config.
Config must return an array: field_id => waContactField OR array of
options to specify on existing field with given field_id.
Parameters
- $file
string|array $file path to config file, or array of config options.
- $options
array $options
|
protected static
|
|
public
|
#
__construct( array $fields = array(), array $options = array() )
Options:
- namespace
- Prefix for all fields of this form.
- Defaults to 'data'.
Options:
- namespace - Prefix for all fields of this form. - Defaults to 'data'.
Parameters
- $fields
array $fields list of waContactField
- $options
array $options
|
public
|
#
setValue( mixed $field_id, mixed $value = null )
Set form value. Note that when POST exists, data from POST overwrite
setValue(). Accepts 1 or 2 parameters.
- 1 parameter: array field_id => value. Set several values.
- 1 parameter: waContact. Fetch data via waContact->load()
- 2 parameters: field_id, value. Set value for single field.
Set form value. Note that when POST exists, data from POST overwrite
setValue(). Accepts 1 or 2 parameters.
- 1 parameter: array field_id => value. Set several values.
- 1 parameter: waContact. Fetch data via waContact->load()
- 2 parameters: field_id, value. Set value for single field.
|
public
mixed
|
#
post( string $field_id = null )
Parameters
- $field_id
string $field_id
Returns
mixed POST data for entire form or single form field; null when no POST submitted.
|
public
|
#
errors( string $field_id = '', string $error_text = null )
Get list of errors for specified field, or append an error to the list.
Get list of errors for specified field, or append an error to the list.
With no parameters returns an array of all errors: field_id => list of
strings.
With one parameter returns a list of errors for one field.
With two parameters appends an error to the list of errors for specified
field. This sets internal state so that form HTML will contain given error
message next to the field. Forces isValid() to return false.
Parameters
- $field_id
string $field_id field_id or null to set message for entire form, not attached to any
field.
- $error_text
string $error_text
|
public
boolean
|
#
isValid( mixed $contact = null )
Validate this form and set internal state so that form HTML will contain
error messages.
Validate this form and set internal state so that form HTML will contain
error messages.
Returns
boolean true when no errors encountered; otherwise false.
|
public
waContactField |waContactField[]
|
#
fields( string $field_id = null )
Get specified form field or all of them.
Get specified form field or all of them.
Parameters
- $field_id
string $field_id
Returns
|
public
|
#
html( string $field_id = null, boolean $with_errors = true )
HTML for the whole form or single form field.
HTML for the whole form or single form field.
Parameters
- $field_id
string $field_id
- $with_errors
boolean $with_errors whether to add class="error" and error text next to form fields
|
public
mixed
|
#
opt( string $name = null, mixed $default = null )
Value of a single option, or the whole options array.
Value of a single option, or the whole options array.
Parameters
- $name
string $name
- $default
mixed $default value to return when no option with this $name specified
Returns
mixed
|
protected
|
#
validateFields( mixed $contact = null )
Make sure POST data is properly validated using waFontactField instances in
$this->fields.
Make sure POST data is properly validated using waFontactField instances in
$this->fields.
|