Formagic main class

Highly extensible form-generator with various rendering options, form validation and sanitation support.

You can use the following options when creating a formagic instance:

attributes
Custom attributes of HTML form tag
action
Form target action
method
Either "post" or "get"
name
Form name
renderer
Name of the renderer to be used. Defaults to "Html". See \#setRenderer for details.
trackSubmission
Enable or disable detailed submission tracking. If enabled, Formagic will be able to track the submission status of all Formagic forms on a HTML page (having trackSubmission enabled). If disabled, the method \#isSubmitted will always return TRUE if any form on a page is submitted.
Defaults to TRUE. Disable only if submission tracking feature causes problems.
translator
Translator implementation. See \#setTranslator for details.
package Formagic
author Florian Sonnenburg
since 0.1.0 First time introduced

 Methods

Proxies method calls to underlying container $this->_itemHolder.

__call(string $method, array $args) : mixed

Parameters

$method

string

Method name string.

$args

array

Array of method parameters.

Exceptions

\Formagic_Exception if called method is not found in item holder

Returns

mixedThe container method result.

Constructor.

__construct(array $options = null

Parameters

$options

array

Array of options for the form.

Exceptions

\Formagic_Exception

Member overloading: Tries to return a form item with member's name.

__get(string $itemName) : \Formagic_Item_Abstract

Parameters

$itemName

string

Name of requested member.

Exceptions

\Formagic_Exception

Returns

\Formagic_Item_AbstractItem object

Will throw an Formagic_Exception, because member overloading is not allowed.

__set(string $key, mixed $value) : void

Parameters

$key

string

Member name

$value

mixed

Member value

Exceptions

\Formagic_Exception

Returns result for string casting of Formagic object.

__toString() : string

Returns

stringThe rendering result.

Allows subclass initialization.

_init() : void

Creates and returns FormagicItem object

createItem(string $type, string $name, array $args = array()) : \Formagic_Item_Abstract
Static

Tries to load correct object class and creates new object. Returns object if successful, throws Formagic_Exception if not

Parameters

$type

string

Item type string

$name

string

Item name

$args

array

Item options array

Exceptions

\Formagic_Exception if item class not found

Returns

\Formagic_Item_AbstractNew item instance

Returns current form action

getFormAction() : string

Returns

stringForm action string

Returns form information string.

getInfo() : string

Returns

stringThe form information string.

Returns root container.

getItemHolder() : \Formagic_Item_Container

Returns

\Formagic_Item_ContainerItem holder item

Returns the form method.

getMethod() : string

Returns

stringThe form submit method.

Returns current form name

getName() : string

Returns

string

Returns unvalidated and unfiltered submit values.

getRaw() : array

Returns

arrayValues array

Returns the current renderer object.

getRenderer() : \Formagic_Renderer_Interface

Returns

\Formagic_Renderer_InterfaceThe renderer object

Returns submission tracking status.

getTrackSubmission() : boolean

Returns

booleanSubmission tracking status.

Returns translator object.

getTranslator() : \Formagic_Translator_Interface
Static

If no translator is specified, an empty translator object is returned.

Returns

\Formagic_Translator_InterfaceThe translator object

Returns array with values from all added items.

getValues() : array

Returns

arrayArray of form item values

Checks if HTML form is submitted

isSubmitted() : boolean

Check result is true for following rules:

  • if submission tracking is enabled in Formagic options and the submission variable is present
  • if submission tracking is disabled, but either GET or POST values (dependent on chosen submission method) are present

Returns

booleanSubmission status

Returns output generated by renderer

render() : string

Loads renderer class and calls renderer::fetch()

Returns

stringRenderer result

Sets the form action URL.

setFormAction(string $value) : \Formagic

Parameters

$value

string

Form action URL

Exceptions

\Formagic_Exception if action value is not a string

Returns

\FormagicFluent interface

Sets the form's submit method.

setMethod(string $method) : \Formagic

Parameters

$method

string

The new form submit method

Exceptions

\Formagic_Exception if method is not supported

Returns

\FormagicFluent interface

Sets form name and thus name of trackSubmission item.

setName(string $name) : \Formagic

Parameters

$name

string

Returns

\FormagicFluent interface

Defines renderer for current Formagic object

setRenderer(string|\Formagic_Renderer_Interface $renderer) : \Formagic

Parameters

$renderer

string\Formagic_Renderer_Interface

Formagic_Renderer object or string with name of renderer class

Exceptions

\Formagic_Exception if renderer is invalid

Returns

\FormagicFluent interface

Enables or disables submission tracking.

setTrackSubmission(boolean $flag) : \Formagic

Parameters

$flag

boolean

Track submission status

Returns

\FormagicFluent interface

Sets translator object and method if present.

setTranslator(array|object|\Formagic_Translator_Interface $translatorDefinition = null) : \Formagic
Static

$translator has to be either an array with two members, the first one being the translator object and the second one the name of the translator method, or a translator object. In the latter case the translator method is assumed '$translatorObject->_($string)'.

Parameters

$translatorDefinition

arrayobject\Formagic_Translator_Interface

One of the following:

  • Array with translator object and method
  • any translator object
  • Formagic_Translator object

Returns

\FormagicFluent interface

Sets default values.

setValues(array $values) : \Formagic

Parameters

$values

array

Form values

Returns

\FormagicFluent interface

Checks if form is submitted and all rules apply

validate() : boolean

Iterates through all items added to the form. If any rule is violated, iteration is stopped. Returns true if no rules are violated. The result of validate() is cached.

todo Think of a better solution for setValues() in line 611

Returns

booleanValidation result

Sets Formagic options.

_setOptions(array $options) : void

Parameters

$options

array

Array of Formagic options

Exceptions

\Formagic_Exception If an option is not supported.

Returns the track submission item.

_getTrackSubmissionItem() : \Formagic_Item_Hidden

Returns

\Formagic_Item_HiddenTrack submission item

 Properties

 

Form submission method ("post" or "get")

$_method : string

Default

'post'
 

Array of submitted values

$_submitValues : array

Default

array()
 

Submit methods supported by Formagic

$_supportedMethods : array

Default

array('get', 'post')
 

Formagic_Translator object

$_translator : \Formagic_Translator_Interface

Default

Static
 

Action for form tag

$_formAction : string

Default

 

Container item holding all items added to Formagic object

$_itemHolder : \Formagic_Item_Container

Default

 

Form name

$_name : string

Default

'formagic'
 

Type of renderer used to display form

$_renderer : \Formagic_Renderer_Interface

Default

see
 

Track submission item

$_submissionItem : \Formagic_Item_Hidden

Default

 

Enables or disables submission tracking

$_trackSubmission : boolean

Default

true

 Constants

 

Formagic API version

API_VERSION = '2.5' 
 

Formagic version

VERSION = '1.5.3'