Structures_Form
[ class tree: Structures_Form ] [ index: Structures_Form ] [ all elements ]

Class: Structures_Form

Source Location: /Structures_Form-0.8.0devel/Form.php

Class Overview


A package designed to make creating input forms easy for PHP-GTK 2 packages and applications.


Author(s):

  • Scott Mattocks

Version:

  • 0.8.0devel

Copyright:

  • Copyright 2006 Scott Mattocks

Variables

Methods


Inherited Variables

Inherited Methods


Class Details

[line 39]
A package designed to make creating input forms easy for PHP-GTK 2 packages and applications.

This package was designed to make it easy to add forms to PHP-GTK 2 packages and applications. The package is modeled after HTML_QuickForm but cannot extend HTML_QuickForm because HTML_QuickForm is tied too tightly to HTML.

PHP-GTK 2 forms are very similar to HTML forms. They consist of a handful of different input types and the data is submitted all together when a user clicks the submit button. The difference is how the user values are submitted and stored. HTML forms submit data in an HTTP request using either GET or POST. PHP-GTK 2 forms call a callback which is then responsible for retrieving the values.

In HTML_QuickForm, all form elements extend a common base class. In PHP-GTK 2 this is not possible because the elements need to be added to containes. To be added to a container a class must extends GtkWidget. While it is not possible to force all form elements to inherit from the same base class we can use an interface to enforce some consistency.

In order to make it possible to create elements on the fly without restricting the number of constructor arguments this package must use the Reflection API. This means that the user must have reflection enabled.

  • Author: Scott Mattocks
  • Version: 0.8.0devel
  • Copyright: Copyright 2006 Scott Mattocks
  • Todo: At least one group class.
  • Todo: Element classes (Done: Text, Password, Submit, Cancel)
  • Todo: Unit tests
  • Todo: Rule classes (Done: Required)
  • License: PHP


[ Top ]


Class Variables

$defaultRenderer =

[line 189]

The default renderer class defined by the element set.
  • Access: protected

Type:   string


[ Top ]

$defaultRendererPath =

[line 197]

The path to the default renderer defined by the element set.
  • Access: protected

Type:   string


[ Top ]

$defaults = array()

[line 162]

The default values for the form elements.
  • Access: protected

Type:   array


[ Top ]

$elements = array()

[line 106]

The form elements.
  • Access: protected

Type:   array


[ Top ]

$errorCallback =

[line 146]

The callback for error handling.
  • Var: string or array
  • Access: protected

Type:   mixed


[ Top ]

$errorMsgs = array(
              Structures_Form::ERROR_ADD_ELEMENT_DOUBLEADD =>
              'Cannot add the element. The element or element name already exists in the form.',
              Structures_Form::ERROR_ADD_RULE_DOUBLEADD =>
              'Cannot create the rule. A rule of this type already exists in the form',
              Structures_Form::ERROR_UNREGISTERED_ELEMENT =>
              'Cannot add the element. The type is not registered.',
              Structures_Form::ERROR_UNREGISTERED_RULE =>
              'Cannot add the rule. The type is not registered.',
              Structures_Form::ERROR_REGISTRATION_ELEMENT =>
              'An error occured while trying to register the element.',
              Structures_Form::ERROR_REGISTRATION_ELEMENT_DOUBLEREG =>
              'The element could not be registered. An element of this type or with the same name is already registered.',
              Structures_Form::ERROR_REGISTRATION_RULE =>
              'An error occured while trying to register the rule.',
              Structures_Form::ERROR_REGISTRATION_RULE_DOUBLEREG =>
              'The rule could not be registered. A rule of this type or with the same name is already registered.',
              Structures_Form::ERROR_UNREGISTRATION_ELEMENTINUSE =>
              'The element could not be unregistered. It is currently in use.',
              Structures_Form::ERROR_UNREGISTRATION_ELEMENT =>
              'An error occured while trying to unregister the element.',
              Structures_Form::ERROR_UNREGISTRATION_RULEINUSE =>
              'The rule could not be unregistered. It is currently in use.',
              Structures_Form::ERROR_UNREGISTRATION_RULE =>
              'An error occured while trying to unregister the rule.',
              Structures_Form::ERROR_LACKSINTERFACE_ELEMENT =>
              'The element could not be added to the form. It does not implement the needed interface.',
              Structures_Form::ERROR_LACKSINTERFACE_ELEMENTSET =>
              'The element set could not be registered. It does not implement the needed interface.',
              Structures_Form::ERROR_LACKSINTERFACE_RULE =>
              'The rule could not be added to the form. It does not implement the needed interface.',
              Structures_Form::ERROR_LACKSINTERFACE_GROUP =>
              'The element group could not be added. It does not implement the needed interface.',
              Structures_Form::ERROR_LACKSINTERFACE_RENDERER =>
              'The renderer could not be set. It does not implement the needed interface.',
              Structures_Form::ERROR_NONEXISTENT_CLASS =>
              'The class does not exist.',
              Structures_Form::ERROR_NONEXISTENT_FILE => 
              'The file could not be read or does not exist.',
              Structures_Form::ERROR_NONEXISTENT_ELEMENT =>
              'The element does not exist.',
              Structures_Form::ERROR_NONEXISTENT_CALLBACK =>
              'The callback does not exist.',
              Structures_Form::ERROR_RENDER_FAILURE =>
              'An error occurred while trying to render the form.'
              )

[line 222]

An array relating error codes to error messages.
  • Access: protected

Type:   array


[ Top ]

$registeredElements = array()

[line 122]

The registered element types.
  • Access: protected

Type:   array


[ Top ]

$registeredRules = array()

[line 130]

The registered rules.
  • Access: protected

Type:   array


[ Top ]

$renderedForm =

[line 213]

The rendered form.
  • Access: protected

Type:   mixed


[ Top ]

$renderer =

[line 205]

The object responsible for displaying the form.
  • Access: public

Type:   object


[ Top ]

$requiredNote =  ' denotes required field'

[line 171]

A note identifying the required field marker.

The renderer should prepend the required symbol to the note.

  • Access: protected

Type:   string


[ Top ]

$requiredSymbol =  '*'

[line 181]

A symbol identifying the required fields.

The renderer should provide some sort of formatting to make the symbol standout.

  • Access: protected

Type:   string


[ Top ]

$rules = array()

[line 114]

The rules to be applied to each element.
  • Access: protected

Type:   array


[ Top ]

$submitCallback =

[line 138]

The method to call after values are collected from a submitted form.
  • Var: string or array
  • Access: protected

Type:   mixed


[ Top ]

$submitObjects =

[line 154]

Send the widgets to the callback instead of the values.
  • Access: protected

Type:   boolean


[ Top ]



Method Detail

__construct (Constructor)   [line 294]

void __construct( mixed $callback, [boolean $submitObjects = false], [mixed $errorCallback = null])

Constructor. Sets the callbacks then registers any default element or rule types.

A callback must be passed in so that the form knows what to do with the values that are collected by the form. Optionally, the user may tell the form to pass the widgets themselves, not the values, to the callback. The user may also define an error callback, which will be called if any rules are viloated. If no error callback is defined, the default callback ($this->defaultErrorCallback()) will be used. The default just passes the errors on to the renderer.

  • Throws: Structures_Form_Exception
  • Access: public

Parameters:

mixed   $callback   —  The method to call when the form is submitted.
boolean   $submitObjects   —  Send the widgets to the callback not the values.
mixed   $errorCallback   —  A callback for handling errors.

[ Top ]

addElement   [line 523]

object A addElement( string $type, string $name)

Creates and adds an element to the form.

Only elements types that are registered with Structures_Form may be added to the form. This helps to ensure that the elements implement the proper interface.

To avoid overhead, type registration is not checked until the type is added to the form.

This method passes any extra arguments on to the element constructor. This allows one method to be used for creating many types of elements. The exact number and type of arguments that is passed to this method varies depending on the type of element to be created. If the wrong number or type of arguments is passed, the element constructor should throw an exception.

An exception may be thrown by createElement or addElementObject. If so it will be bubble up through this method.

  • Return: Structures_Form element
  • Throws: Structures_Form_Exception
  • Access: public

Parameters:

string   $type   —  The element type.
string   $name   —  The element name.

[ Top ]

addElementObject   [line 739]

object The addElementObject( object $element)

Adds an element to the form.

Only elements types that are registered with Structures_Form may be added to the form. This helps to ensure that the elements implement the proper interface.

To avoid overhead, type registration is not checked until the type is added to the form.

  • Return: added element.
  • Access: public

Parameters:

object   $element   — 

[ Top ]

addElementObjectToGroup   [line 1210]

boolean addElementObjectToGroup( string $element, string $group)

Adds an element object to a group.

A group is just a way to logically and visually group form elements. Elements can be added to or removed from a group without removing them from the form all together. However, obviously if the element is removed from the form, it will be removed from the group. If you readd the same element object, it will NOT be readded to the group.

This method returns true if the element has been added to the group and false in all other cases including when the element is not part of the form or the group does not exist.

Elements may only be part of one group. If the element is already part of another group, it will not be added to this group.

An element must be part of the form before it can be added to the group. This is normally not a problem as elements should be created using addElement or createElement.

  • Return: true if the element has been added to the group.
  • Access: public

Parameters:

string   $element   —  The element.
string   $group   —  The name of the group.

[ Top ]

addElementToGroup   [line 1131]

boolean addElementToGroup( string $name, string $group)

Adds an element to a group.

A group is just a way to logically and visually group form elements. Elements can be added to or removed from a group without removing them from the form all together. However, obviously if the element is removed from the form, it will be removed from the group. If you readd the same element object, it will NOT be readded to the group.

Elements may only be part of one group. If the element is already part of another group, it will not be added to this group.

  • Return: true if the element has been added to the group.
  • Access: public

Parameters:

string   $name   —  The name of the element.
string   $group   —  The name of the group.

[ Top ]

addRule   [line 1705]

boolean addRule( string $name, string $rule)

Associates a rule with a form element.

When a form is submitted, the values will be checked against any rules that have been associated with the elements. A rule of a give type can only be added to an individual element once. Attempting to add a rule to the same element twice will have no extra effect.

This method passes any extra arguments on to the rule constructor. This allows one method to be used for creating many types of rules. The exact number and type of arguments that is passed to this method varies depending on the type of rule to be created. If the wrong number or type of arguments is passed, the rule constructor should throw an exception.

  • Return: true if the rule was applied.
  • Access: public

Parameters:

string   $name   —  The name of the element.
string   $rule   —  The name of the rule.

[ Top ]

addRuleToObject   [line 1879]

boolean addRuleToObject( object $element, string $rule)

Associates a rule with a form element object.

When a form is submitted, the values will be checked against any rules that have been associated with the elements. A rule of a give type can only be added to an individual element once. Attempting to add a rule to the same element twice will have no extra effect.

This method passes any extra arguments on to the rule constructor. This allows one method to be used for creating many types of rules. The exact number and type of arguments that is passed to this method varies depending on the type of rule to be created. If the wrong number or type of arguments is passed, the rule constructor should throw an exception.

  • Return: true if the rule was applied.
  • Access: public

Parameters:

object   $element   —  The form element object
string   $rule   —  The form rule name.

[ Top ]

clearValues   [line 1417]

array clearValues( )

Clears the values of all form elements (if possible).
  • Return: An array of elements whose value has been cleared.
  • Access: public

[ Top ]

createElement   [line 658]

object A createElement( string $type, string $name)

Creates an element but does not add it to the form.

Only elements types that are registered with Structures_Form may be added to the form. This helps to ensure that the elements implement the proper interface.

To avoid overhead, type registration is not checked until the type is added to the form.

This method passes any extra arguments on to the element constructor. This allows one method to be used for creating many types of elements. The exact number and type of arguments that is passed to this method varies depending on the type of element to be created. If the wrong number or type of arguments is passed, the element constructor should throw an exception.

  • Return: Structures_Form element
  • Throws: Structures_Form_Exception
  • Access: public

Parameters:

string   $type   —  The element type.
string   $name   —  The element name.

[ Top ]

createRule   [line 1760]

boolean createRule( string $rule)

Creates a rule object.

When a form is submitted, the values will be checked against any rules that have been associated with the elements. A rule of a give type can only be added to an individual element once. Attempting to add a rule to the same element twice will have no extra effect.

This method passes any extra arguments on to the rule constructor. This allows one method to be used for creating many types of rules. The exact number and type of arguments that is passed to this method varies depending on the type of rule to be created. If the wrong number or type of arguments is passed, the rule constructor should throw an exception.

  • Return: true if the rule was applied.
  • Access: public

Parameters:

string   $rule   —  The name of the rule.

[ Top ]

defaultErrorCallback   [line 1529]

void defaultErrorCallback( array $errors)

Simply passes the error array on to the renderer.

It might be a good idea to re-render the form after errors are added but that is the responsibility of the developer and the renderer. It cannot be determined here if the user wants to re-render. Nor can the form reliably be changed form here.

If errors need to be handled in a different way, you should set a custom error callback either when the form is constructed or by using setErrorCallback().

  • Access: public

Parameters:

array   $errors   —  An array of error messages.

[ Top ]

disbandGroup   [line 1016]

array disbandGroup( string $group)

Disbands a group.

This method disbands a group. It does not destroy the elements in the group or even remove them from the form. It simply disbands the group and makes the elements free floating individuals. The elements are inserted where the group used to be.

This method returns an array containing the names of any elements that were in the group before it was disbanded.

If the group does not exist, this method will return an empty array.

  • Access: public

Parameters:

string   $group   —  The name of the group to disband.

[ Top ]

elementExists   [line 957]

boolean elementExists( string $name)

Returns whether or not the given element is associated with this form.
  • Return: true if the element is part of this form.
  • Access: public

Parameters:

string   $name   —  The name of the element to check.

[ Top ]

elementObjectExists   [line 971]

boolean elementObjectExists( object $element)

Returns whether or not the element object is associated with this form.
  • Return: true if the element is part of the form.
  • Access: public

Parameters:

object   $element   —  The element object.

[ Top ]

getAllElements   [line 945]

array getAllElements( )

Returns an array of all elements.
  • Return: An array of elements array(<name> => <element>)
  • Access: public

[ Top ]

getDefaultRenderer   [line 2094]

object. getDefaultRenderer( )

Creates a default renderer object.

This method may be called by group elements that need to renderer elements but do not have a renderer set.

  • Access: public

[ Top ]

getDefaults   [line 1472]

array getDefaults( )

Returns the array of default values.
  • Access: public

[ Top ]

getElement   [line 923]

mixed getElement( string $name)

Returns the form element with the given name.
  • Return: Either the object or false if the object was not found.
  • Access: public

Parameters:

string   $name   —  The element name.

[ Top ]

getElementsByType   [line 903]

array getElementsByType( string $type)

Returns all of the elements in the form of the given type.
  • Access: public

Parameters:

string   $type   —  The element type name.

[ Top ]

getErrorCallback   [line 352]

mixed getErrorCallback( )

Returns the error callback.
  • Return: A string or array.
  • Access: public

[ Top ]

getErrorMessage   [line 489]

string getErrorMessage( integer $errorCode)

Returns an error message for the given error code.
  • Return: An error message.
  • Access: public

Parameters:

integer   $errorCode   —  The error code to get a message for.

[ Top ]

getGroup   [line 1086]

array getGroup( string $group)

Returns the group element.

If the group does not exists, this method returns false.

  • Access: public

Parameters:

string   $group   —  The name of the group.

[ Top ]

getGroupElements   [line 1280]

array getGroupElements( string $name)

Returns an array containing the names of the elements in the given group.

If the group does not exist, this method returns an empty array.

  • Access: public

Parameters:

string   $name   —  The name of the group

[ Top ]

getGroups   [line 1101]

array getGroups( )

Returns an array containing all groups.
  • Access: public

[ Top ]

getPosition   [line 991]

integer getPosition( string $name)

Returns the current position of the element.
  • Return: The current position.
  • Access: public

Parameters:

string   $name   —  The element name.

[ Top ]

getRenderedForm   [line 2188]

object The getRenderedForm( )

Returns the most recently rendered widget.

This method will not render the form! It only returns the widget created when render() was called!

  • Return: rendered form.
  • Access: public

[ Top ]

getRequiredNote   [line 1978]

string getRequiredNote( )

Returns the current required note.
  • Access: public

[ Top ]

getRequiredSymbol   [line 2001]

string getRequiredSymbol( )

Returns the current required symbol.
  • Access: public

[ Top ]

getSubmitCallback   [line 341]

mixed getSubmitCallback( )

Returns the submit callback.
  • Return: A string or array.
  • Access: public

[ Top ]

getValue   [line 1330]

mixed getValue( string $name)

Returns the current value for the given element.
  • Return: The value of the element or group of elements.
  • Throws: Structures_Form_Exception
  • Access: public

Parameters:

string   $name   —  The element name.

[ Top ]

getValues   [line 1304]

array getValues( )

Returns the current value for all elements in an associative array.

The array will be of the form: array(<name> => <value>);

  • Access: public

[ Top ]

groupExists   [line 1051]

boolean groupExists( $group, string $name)

Returns whether or not the given group exists in this form.
  • Return: true if the group exists.
  • Access: public

Parameters:

string   $name   —  The name of the group.
   $group   — 

[ Top ]

insertElement   [line 555]

object The insertElement( object $element, [ $position = -1])

Inserts an element object at the given location.

Only elements types that are registered with Structures_Form may be added to the form. This helps to ensure that the elements implement the proper interface.

To avoid overhead, type registration is not checked until the type is added to the form.

  • Return: inserted object.
  • Access: public

Parameters:

object   $element   —  The element object.
   $position   — 

[ Top ]

isElementRegistered   [line 874]

boolean isElementRegistered( string $type, [string $class = null])

Returns whether or not an element type is registered.
  • Return: true if the element type is registered.
  • Access: public

Parameters:

string   $type   —  The name of the element type.
string   $class   —  Optional class name to check.

[ Top ]

isGroup   [line 1071]

boolean isGroup( object $element)

Returns whether or not the element is a group.
  • Return: true if the element is an group.
  • Access: public

Parameters:

object   $element   —  The element to check.

[ Top ]

isIncludable   [line 819]

boolean isIncludable( string $path)

Returns whether or not a path is in the include path.
  • Return: true if the path is in the include path.
  • Access: public

Parameters:

string   $path   — 

[ Top ]

isRequired   [line 2013]

boolean isRequired( string $element)

Returns whether or not an element is required.
  • Return: true if the required rule is applied to the element.
  • Access: public

Parameters:

string   $element   —  The name of the element.

[ Top ]

isRuleApplied   [line 1941]

boolean isRuleApplied( string $name)

Returns whether or not the give rule is currently associated with any form elements.
  • Return: true if the rule is currently associated with an element
  • Access: public

Parameters:

string   $name   —  The name of the form rule to check.

[ Top ]

isRuleAppliedToElement   [line 2031]

boolean isRuleAppliedToElement( string $element, string $rule)

Returns whether or not the given rule is applied to the given element.

This method returns true if the rule is applied to the element and false in all other cases including if the rule or element is not defined.

  • Return: true if the rule is applied to the element.
  • Access: public

Parameters:

string   $element   —  The name of the element.
string   $rule   —  The name of the rule.

[ Top ]

isRuleRegistered   [line 1664]

boolean isRuleRegistered( string $rule, [string $class = null])

Returns whether or not a rule is registered.
  • Return: true if the rule is registered.
  • Access: public

Parameters:

string   $rule   —  The name of the rule type.
string   $class   —  Optional class name to check.

[ Top ]

moveElement   [line 626]

object The moveElement( object $element, integer $position)

Moves an element object from its current position to the given position.

If the position is greater than the number of elements, the element will be added to the end of the form.

  • Return: object that was moved.
  • Access: public

Parameters:

object   $element   —  The element to move.
integer   $position   —  The new position.

[ Top ]

registerDefaultRules   [line 441]

void registerDefaultRules( )

Registers the default rule types.

Rule objects are used to validate the values of the form elements before they are submitted to the callback. If an elements value violates a rule a rule callback will be called which allows the user to handle errors in their own way. All violations are collected on each submit and then passed off to the rule callback.

Only registered rules may be applied to a form element.

All registered rules must implement the Structures_Form_RuleInterface.

To avoid overhead, a rule is not checked until it is applied to a form element.

  • Access: protected

[ Top ]

registerElement   [line 785]

boolean registerElement( string $name, string $class, string $path)

Registers an element type with this form.

Before an element type can be used in a form, it must be registered. Registering an element type helps to make sure that type names are unique and that element classes implement the needed interface.

To avoid overhead, registered classes are not checked until the type is instantiated.

  • Return: true if the class was registered
  • Throws: Structures_Form_Exception
  • Access: public

Parameters:

string   $name   —  The name to identify the element type.
string   $class   —  The name of the element class.
string   $path   —  The path to the class definition.

[ Top ]

registerElementSet   [line 377]

boolean registerElementSet( string $elementSet)

Registers a set of elements.

Only elements types that are registered with Structures_Form may be added to the form. This helps to ensure that the elements implement the proper interface.

Element sets must also define a default renderer.

To avoid overhead, type registration is not checked until the type is added to the form.

registerElement may throw an exception that will be passed along to the calling code.

  • Return: true if the element set was registered.
  • Throws: Structures_Form_Exception
  • Access: public

Parameters:

string   $elementSet   —  The name of an element set.

[ Top ]

registerRule   [line 1594]

boolean registerRule( string $name, string $class, string $path)

Registers a rule class with the form.

Rule objects are used to validate the values of the form elements before they are submitted to the callback. If an elements value violates a rule a rule callback will be called which allows the user to handle errors in their own way. All violations are collected on each submit and then passed off to the rule callback.

Only registered rules may be applied to a form element.

All registered rules must implement the Structures_Form_RuleInterface.

To avoid overhead, a rule is not checked until it is applied to a form element.

  • Return: true if the rule was registered.
  • Throws: Structures_Form_Exception
  • Access: public

Parameters:

string   $name   —  A name to identify the rule.
string   $class   —  The name of the rule class.
string   $path   —  The path to the class definition.

[ Top ]

removeElement   [line 718]

void removeElement( string $name)

Removes an element from the form by name.
  • Access: public

Parameters:

string   $name   — 

[ Top ]

removeElementFromGroup   [line 1164]

object The removeElementFromGroup( string $element, string $group)

Removes an element from a group.

A group is just a way to logically and visually group form elements. Elements can be added to or removed from a group without removing them from the form all together. However, obviously if the element is removed from the form, it will be removed from the group. If you readd the same element object, it will NOT be readded to the group.

  • Return: object that was removed or false
  • Access: public

Parameters:

string   $element   —  The name of the element.
string   $group   —  The name of the group.

[ Top ]

removeElementObject   [line 755]

void removeElementObject( object $element)

Removes an element object from the form.

This method is useful if an element has been added with the wrong name. Trying to remove it by the name returned by getName() will not work so you must remove it by the object.

  • Access: public

Parameters:

object   $element   — 

[ Top ]

removeElementObjectFromGroup   [line 1249]

object The removeElementObjectFromGroup( string $element, string $group)

Removes an element object from a group.

A group is just a way to logically and visually group form elements. Elements can be added to or removed from a group without removing them from the form all together. However, obviously if the element is removed from the form, it will be removed from the group. If you readd the same element object, it will NOT be readded to the group.

This method returns true if the element has been removed from the group and false in all other cases including when the element is not part of the form or the group does not exist.

  • Return: object that was removed or false.
  • Access: public

Parameters:

string   $element   —  The element.
string   $group   —  The name of the group.

[ Top ]

removeRule   [line 1836]

boolean removeRule( string $element, string $rule)

Removes a rule from an element.

When a form is submitted, the values will be checked against any rules that have been associated with the elements. A rule of a give type can only be added to an individual element once. Attempting to add a rule to the same element twice will have no extra effect. Therefore, it only makes sense to try to remove a rule once.

This method will return true if the rule is not associated with the element. This means that it will also return true even if the rule was never associated with the element in the first place.

  • Return: true if the rule is no longer associated with the element
  • Access: public

Parameters:

string   $element   —  The name of the element to remove the rule from
string   $rule   —  The name of the rule to remove

[ Top ]

removeRuleFromObject   [line 1917]

boolean removeRuleFromObject( object $element, string $rule)

Removes a rule from a form element object.

When a form is submitted, the values will be checked against any rules that have been associated with the elements. A rule of a give type can only be added to an individual element once. Attempting to add a rule to the same element twice will have no extra effect. Therefore, it only makes sense to try to remove a rule once.

This method will return true if the rule is not associated with the element. This means that it will also return true even if the rule was never associated with the element in the first place.

  • Return: true if the rule is no longer associated with the element
  • Access: public

Parameters:

object   $element   —  The form element to remove the rule from.
string   $rule   —  The rule to remove from the object.

[ Top ]

render   [line 2139]

object A render( )

Returns a container widget holding the form elements.

Passes the elements, required note and required symbol to the renderer and then calls renderer().

Pulling elements out of a renderer is a pain in the ass. Trying to find the correct widget (or parent widget) can be nearly impossible. Therefore, even if you remove a widget from the form, it will still appear if the widget was removed after the form was rendered.

  • Return: container widget holding the form.
  • Throws: Structures_Form_Exception
  • Access: public

[ Top ]

restoreDefaults   [line 1461]

array restoreDefaults( )

Restores the elements to their default values.

This method over writes any values currently set!

If no defaults were set, this method will return an empty array.

  • Return: An array containing names of elements whose value has changed.
  • Access: public

[ Top ]

ruleExists   [line 1955]

boolean ruleExists( string $rule)

Returns whether or not a rule with the given name already exists.
  • Return: true if the name is in use.
  • Access: public

Parameters:

string   $rule   —  The name fo the rule.

[ Top ]

setDefaultRenderer   [line 2115]

void setDefaultRenderer( )

Creates a default renderer and sets it as the current renderer.

An exception may be thrown by setRenderer. It will pass through to the calling function.

  • Access: protected

[ Top ]

setDefaults   [line 1441]

array setDefaults( array $defaults)

Sets the values of the elements and make the given values the defautls.

This method over writes any values currently set!

  • Return: An array containing names of elements whose value has changed.
  • Access: public

Parameters:

array   $defaults   —  An array of default values.

[ Top ]

setErrorCallback   [line 330]

void setErrorCallback( mixed $callback)

Sets the error callback.
  • Access: public

Parameters:

mixed   $callback   —  A string or array.

[ Top ]

setRenderer   [line 2064]

void setRenderer( object $renderer)

Sets a renderer object.

Renderers must implement Structures_Form_RendererInterface. This helps to ensure consistency among the API and avoid any fatal errors. A renderer is used to position and display the form elements within a container widget.

Unlike rules and elements, renderers are created on their own (not through a form method). This is because they do not need to know thing about the form at construction time and the form does not need to know anything about the renderer until the form is to be displayed.

A form may only have one renderer at a time. Setting a second renderer will overwrite the first. If no renderer is set, the default renderer will be used.

  • Throws: Structures_Form_Exception
  • Access: public

Parameters:

object   $renderer   —  An object that implements Structures_Form::RENDERER_INTERFACE

[ Top ]

setRequiredNote   [line 1967]

void setRequiredNote( string $note)

Sets the require note.
  • Access: public

Parameters:

string   $note   —  The text to use.

[ Top ]

setRequiredSymbol   [line 1990]

void setRequiredSymbol( string $symbol)

Sets the require symbol.
  • Access: public

Parameters:

string   $symbol   —  The text to use.

[ Top ]

setValue   [line 1392]

boolean setValue( string $name, mixed $value)

Sets the value for the given element.

This method returns true if the value appears to have been changed. If false is returned, it may indicated that the element does not exist, that the new value was the same as the old value, or that it was frozen.


Parameters:

string   $name   —  The name of the element
mixed   $value   —  The element value.

[ Top ]

setValues   [line 1361]

array setValues( array $values)

Sets the values for the form elements.

The array passed in should be of the form: array(<name> => <value>)


Parameters:

array   $values   —  An array of values.

[ Top ]

submit   [line 1483]

boolean submit( )

Collects submitted values and calls the callback or error callback.
  • Return: false to continue processing callbacks.
  • Access: public

[ Top ]

swapElementSet   [line 2206]

boolean swapElementSet( Structures_Form_ElementSet $elementSet)

Changes the UI of the form from the current set of elements to the given element set.

This method allows you to quickly and easily change from one element set to another. In most cases it is only necessary to change renderers but some renderers may have additional requirements for the elements that necessitate changing the classes that represent the elements.

  • Return: true if the element set was changed successfully.
  • Access: public

Parameters:

object   $elementSet   —  A Structures_Form_Element set.

[ Top ]

unRegisterElement   [line 850]

boolean unRegisterElement( string $type)

Unregisters an element type with a form.

An element type may not be unregistered if the form contains elements of the given type.

You may want to unregister a type to prevent a certain type from being used in the form. For example if your app creates forms on the fly from user supplied data, you can unregister the text type to prevent users from creating a form with free form text entries.

  • Return: true if the type was unregistered
  • Throws: Structures_Form_Exception
  • Access: public

Parameters:

string   $type   —  The element type name.

[ Top ]

unRegisterRule   [line 1640]

boolean unRegisterRule( string $name)

Unregisters a rule with the form.

Only registered rules may be applied to a form element.

A rule may not be unregistered if it is currently being applied to one or more form elements.

You may want to unregister a rule to prevent it from being applied to a form. For example, if your app creates forms on the fly, you may want to unregister a rule to prevent the user from applying a rule that their PHP installation cannot support (regular expressions may not be available).

  • Return: true if the rule was unregistered.
  • Throws: Structures_Form_Exception
  • Access: public

Parameters:

string   $name   —  The name of the rule class.

[ Top ]

validate   [line 1549]

array validate( )

Validates the values of the form against the applied rules.

This method returns an array even if there are no errors. If the array is empty, then no errors occurred or no rules were applied.

  • Return: An array of error messages
  • Access: public

[ Top ]


Documentation generated on Mon, 11 Mar 2019 14:44:13 -0400 by phpDocumentor 1.4.4. PEAR Logo Copyright © PHP Group 2004.