Formagic main and interface class

Highly extensible formgenerator with various rendering options, form validation and multipage 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
pluginBaseDir
Base directory of custom Formagic extension classes. It is assumed that a standard directory structure, similar to the Formagic directory structre, can be found inside the base dir:
 - BaseDir
   |- Filter
   |- Item
   |- Renderer
   ^- Rule
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.

category Formagic
package Formagic
author Florian Sonnenburg
copyright Copyright (c) 2007-2012 Florian Sonnenburg
version $Id: Formagic.php 169 2012-05-06 20:16:16Z meweasle $, $Revision: 70 $

 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.

Returns

mixedThe container method result.

Constructor.

__construct(array $options) 

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

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

Adds a directory to base dir stack (globally for all Formagic instances).

addBaseDir(string $baseDir) : void

Parameters

$baseDir

string

BaseDir to be added

Creates and returns FormagicItem object

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

Tries to load correct object class and creates new object. Returns object if successfull, false if not.

Parameters

$type

string

Item type string

$name

string

Item name

$args

array

Item options array

Returns

\Formagic_Item_AbstractNew item instance

Returns current plugin base directory stack.

getBaseDirs() : array

Returns

arrayPlugin base directory stack

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 undvalidated 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

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

Returns

\Formagic_TranslatorThe 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

Loads a class located in defined baseDir locations.

loadClass(string $class) : void

Skipped if class is already loaded. loadClass() tries to load from any extension directories defined. Returns true if successful, false if not.

Parameters

$class

string

Class name. File name is $class.php

Exceptions

\Formagic_Exception if item class could not be loaded

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

Returns

\FormagicFluent interface

Sets the form's submit method.

setMethod(string $method) : \Formagic

Parameters

$method

string

The new form submit method

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

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 $translatorDefinition) : \Formagic

$translator has to be either an array with two members, the first one beeing 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

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

Sets form name and thus name of trackSubmission item.

_setName(string $name) : \Fluent

Parameters

$name

string

Returns

\Fluentinterface

 Properties

 

Array of directories classes are searched for

$_baseDirs : array

 

Form submission method (POST or GET)

$_method : string

 

Array of submitted values

$_submitValues : array

 

Submit methods supported by Formagic

$_supportedMethods : array

 

Formagic_Translator object

$_translator : \Formagic_Translator

 

Action for form tag

$_formAction : string

 

Container item holding all items added to Formagic object

$_itemHolder : \Formagic_Item_Container

 

Form name

$_name : string

 

Type of renderer used to display form

$_renderer : \Formagic_Renderer

see \Formagic::setRenderer()
 

Track submission item

$_submissionItem : \Formagic_Item_Hidden

 

Enables or disables submission tracking

$_trackSubmission : boolean

 Constants

 

Formagic API version

API_VERSION 

 

Formagic version

VERSION