AnewtFormControl Class Reference

Base form control class. More...

List of all members.

Public Member Functions

 __construct ($name)
 Create a new form control instance.
Validation methods
 is_empty ()
 Check whether this control is to be considered 'empty'.
 is_valid ()
 Check whether this form control is valid.
 add_validator ($validator, $error_message=null)
 Add a validator instance to this form control.
Rendering methods
 build_widget ()
 Render the minimal HTML needed for this control to work.

Protected Attributes

 $_form
 Reference to containing AnewtForm instance.
 $_validators
 List of validators.
 $_validator_errors
 List of validator error messages.

Getter and setter methods

 fill ($values)
 Fill the form control from the given values.
 get_id ()
 Return the form id.
 _set_form ($form)
 Make the control reference its containing form.


Detailed Description

Base form control class.

All form controls must extend this class.

Do not instantiate this class directly, use one of its descendants instead.

Definition at line 18 of file form/controls/base.lib.php.


Constructor & Destructor Documentation

AnewtFormControl::__construct ( name  ) 

Create a new form control instance.

If a subclass overrides the AnewtFormControl constructor, the parent constructor must be invoked as well.

Parameters:
$name The name of this control. It must be unique across this form.

Reimplemented from AnewtContainer.

Reimplemented in AnewtFormControlButton, AnewtFormControlButtonSubmit, AnewtFormControlButtonReset, AnewtFormControlCheckbox, AnewtFormControlChoice, AnewtFormControlTextBase, AnewtFormControlText, AnewtFormControlPassword, and AnewtFormControlTextMultiline.

Definition at line 50 of file form/controls/base.lib.php.


Member Function Documentation

AnewtFormControl::fill ( values  ) 

Fill the form control from the given values.

This only sets the value for controls for which the can-be-filled property is enabled.

The return value of this function indicates whether the control was successfully filled with a value. For some control types such as checkboxes this always succeeds since both presence and absence of the value from $values are meaningful. For other controls such as text inputs this is only true if the value was actually present in the $values parameters.

Parameters:
$values An associative array from which the form control should be filled.
Returns:
true if filling was succesfull, false otherwise.
See also:
AnewtForm::fill()

Reimplemented in AnewtFormControlButtonSubmit, AnewtFormControlCheckbox, AnewtFormControlChoice, and AnewtFormControlFileUpload.

Definition at line 116 of file form/controls/base.lib.php.

AnewtFormControl::get_id (  ) 

Return the form id.

This method falls back to the name value if no id was explicitly provided.

Definition at line 140 of file form/controls/base.lib.php.

AnewtFormControl::_set_form ( form  )  [private]

Make the control reference its containing form.

Parameters:
$form A reference to an AnewtForm instance.

Definition at line 157 of file form/controls/base.lib.php.

AnewtFormControl::is_empty (  ) 

Check whether this control is to be considered 'empty'.

This method is invoked when validating a form. When a control is optional and empty, no validators are applied to it. The base implementation just checks whether the value property is an empty string, but subclasses may do more sensible checks.

Returns:
True if empty, false otherwise.

Definition at line 181 of file form/controls/base.lib.php.

AnewtFormControl::is_valid (  ) 

Check whether this form control is valid.

The default is to apply all validators added to this control. Subclasses could also override this method to do something more sensible than applying validators, since some controls don't accept validators, e.g. checkboxes.

Returns:
True if valid, false otherwise.

Reimplemented in AnewtFormControlChoice, AnewtFormControlFileUpload, and AnewtFormControlTextBase.

Definition at line 196 of file form/controls/base.lib.php.

AnewtFormControl::add_validator ( validator,
error_message = null 
)

Add a validator instance to this form control.

The (optional) error message will be shown when the validator fails to validate the form control.

Parameters:
$validator A validator instance, e.g. AnewtValidatorLength or another AnewtValidator subclass.
$error_message An optional error message to be shown when this validator fails. Leave empty to not show an error.

Definition at line 232 of file form/controls/base.lib.php.

AnewtFormControl::build_widget (  )  [abstract]

Render the minimal HTML needed for this control to work.

Form control implementations should implement this method, e.g. for a checkbox a simple input HTML element should be returned.

Returns:
XHTML element with the minimal HTML markup needed for this control to function properly.

Reimplemented in AnewtFormControlButton, AnewtFormControlCheckbox, AnewtFormControlChoice, AnewtFormControlFileUpload, AnewtFormControlTextBase, and AnewtFormControlHidden.


Member Data Documentation

AnewtFormControl::$_form [protected]

Reference to containing AnewtForm instance.

See also:
_set_form

Definition at line 25 of file form/controls/base.lib.php.

AnewtFormControl::$_validators [protected]

List of validators.

See also:
add_validator

Definition at line 32 of file form/controls/base.lib.php.

AnewtFormControl::$_validator_errors [protected]

List of validator error messages.

See also:
add_validator

Definition at line 39 of file form/controls/base.lib.php.


The documentation for this class was generated from the following file:

Generated on Sun Aug 2 22:54:37 2009 for Anewt by  doxygen 1.5.9