PHP Class Pop\Form\Form

Author: Nick Sagona, III ([email protected])
Inheritance: extends Pop\Dom\Dom
Show file Open project: nicksagona/PopPHP Class Usage Examples

Protected Properties

Property Type Description
$action string Form action
$errorDisplay array Global Form error display format
$fields array Form field values
$form Pop\Dom\Child Form element node
$groups array Form field groups
$hasFile boolean Has file flag
$initFieldsValues array Form init field values
$method string Form method
$template string Form template for HTML formatting.

Public Methods

Method Description
__construct ( string $action = null, string $method = 'post', array $fields = null, string $indent = null ) : Form Constructor
__get ( string $name ) : mixed Get method to return the value of fields[$name].
__isset ( string $name ) : boolean Return the isset value of fields[$name].
__set ( string $name, mixed $value ) : void Set method to set the property to the value of fields[$name].
__toString ( ) : string Output the form object as a string
__unset ( string $name ) : void Unset fields[$name].
addElements ( mixed $e ) : Form Add a form element or elements to the form object.
addFields ( array $fields ) : Form Alias for setFields()
clear ( ) : Form Method to clear any session data used with the form for security tokens, captchas, etc.
factory ( string $action = null, string $method = 'post', array $fields = null, string $indent = null ) : Form Static method to instantiate the form object and return itself to facilitate chaining methods together.
filter ( array $filters ) : Form Method to filter current form values with the applied callbacks and their parameters
getAction ( ) : array Get the form action.
getAttributes ( ) : array Get the attributes of the form object.
getElement ( string $elementName ) : Element Get an element object of the form by name.
getElementIndex ( string $elementName ) : integer Get the index of an element object of the form by name.
getElements ( ) : array Get the elements of the form object.
getErrors ( ) : array Get all form element errors.
getField ( $name ) : array Get a single field from $initFieldsValues
getFields ( ) : array Get the form fields
getFormElement ( ) : array Get the main form element.
getMethod ( ) : array Get the form method.
getTemplate ( ) : string Get the form template for the render method to utilize.
hasFile ( ) : boolean Get the $hasFile property
isValid ( ) : boolean Determine whether or not the form object is valid and return the result.
removeElement ( string $elementName ) Remove a form element
render ( boolean $ret = false ) : void Render the form object either using the defined template or by a basic 1:1 DT/DD tag structure.
setAction ( string $action ) : Form Set the form action.
setAttributes ( array | string $a, string $v = null ) : Form Set an attribute or attributes for the form object.
setErrorDisplay ( string $container, array $attribs, boolean $pre = false ) : Form Set error pre-display globally across all form element objects
setField ( string $name, array $field ) : Form Set a single field in $initFieldsValues
setFieldValues ( array $values = null, array $filters = null ) : Form Set the field values. Optionally, you can apply filters to the passed values via callbacks and their parameters
setFields ( array $fields ) : Form Set the fields of the form object.
setMethod ( string $method ) : Form Set the form method.
setTemplate ( string $tmpl ) : Form Set a form template for the render method to utilize.

Protected Methods

Method Description
filterValues ( array $values, array $filters ) : array Method to filter the values with the applied callbacks and their parameters
renderWithTemplate ( ) : void Method to render the form using the template
renderWithoutTemplate ( ) : void Method to render the form using a basic 1:1 DT/DD layout

Method Details

__construct() public method

Instantiate the form object
public __construct ( string $action = null, string $method = 'post', array $fields = null, string $indent = null ) : Form
$action string
$method string
$fields array
$indent string
return Form

__get() public method

Get method to return the value of fields[$name].
public __get ( string $name ) : mixed
$name string
return mixed

__isset() public method

Return the isset value of fields[$name].
public __isset ( string $name ) : boolean
$name string
return boolean

__set() public method

Set method to set the property to the value of fields[$name].
public __set ( string $name, mixed $value ) : void
$name string
$value mixed
return void

__toString() public method

Output the form object as a string
public __toString ( ) : string
return string

__unset() public method

Unset fields[$name].
public __unset ( string $name ) : void
$name string
return void

addElements() public method

Add a form element or elements to the form object.
public addElements ( mixed $e ) : Form
$e mixed
return Form

addFields() public method

Alias for setFields()
public addFields ( array $fields ) : Form
$fields array
return Form

clear() public method

Method to clear any session data used with the form for security tokens, captchas, etc.
public clear ( ) : Form
return Form

factory() public static method

Static method to instantiate the form object and return itself to facilitate chaining methods together.
public static factory ( string $action = null, string $method = 'post', array $fields = null, string $indent = null ) : Form
$action string
$method string
$fields array
$indent string
return Form

filter() public method

Method to filter current form values with the applied callbacks and their parameters
public filter ( array $filters ) : Form
$filters array
return Form

filterValues() protected method

Method to filter the values with the applied callbacks and their parameters
protected filterValues ( array $values, array $filters ) : array
$values array
$filters array
return array

getAction() public method

Get the form action.
public getAction ( ) : array
return array

getAttributes() public method

Get the attributes of the form object.
public getAttributes ( ) : array
return array

getElement() public method

Get an element object of the form by name.
public getElement ( string $elementName ) : Element
$elementName string
return Element

getElementIndex() public method

Get the index of an element object of the form by name.
public getElementIndex ( string $elementName ) : integer
$elementName string
return integer

getElements() public method

Get the elements of the form object.
public getElements ( ) : array
return array

getErrors() public method

Get all form element errors.
public getErrors ( ) : array
return array

getField() public method

Get a single field from $initFieldsValues
public getField ( $name ) : array
$name
return array

getFields() public method

Get the form fields
public getFields ( ) : array
return array

getFormElement() public method

Get the main form element.
public getFormElement ( ) : array
return array

getMethod() public method

Get the form method.
public getMethod ( ) : array
return array

getTemplate() public method

Get the form template for the render method to utilize.
public getTemplate ( ) : string
return string

hasFile() public method

Get the $hasFile property
public hasFile ( ) : boolean
return boolean

isValid() public method

Determine whether or not the form object is valid and return the result.
public isValid ( ) : boolean
return boolean

removeElement() public method

Remove a form element
public removeElement ( string $elementName )
$elementName string

render() public method

Render the form object either using the defined template or by a basic 1:1 DT/DD tag structure.
public render ( boolean $ret = false ) : void
$ret boolean
return void

renderWithTemplate() protected method

Method to render the form using the template
protected renderWithTemplate ( ) : void
return void

renderWithoutTemplate() protected method

Method to render the form using a basic 1:1 DT/DD layout
protected renderWithoutTemplate ( ) : void
return void

setAction() public method

Set the form action.
public setAction ( string $action ) : Form
$action string
return Form

setAttributes() public method

Set an attribute or attributes for the form object.
public setAttributes ( array | string $a, string $v = null ) : Form
$a array | string
$v string
return Form

setErrorDisplay() public method

Set error pre-display globally across all form element objects
public setErrorDisplay ( string $container, array $attribs, boolean $pre = false ) : Form
$container string
$attribs array
$pre boolean
return Form

setField() public method

Set a single field in $initFieldsValues
public setField ( string $name, array $field ) : Form
$name string
$field array
return Form

setFieldValues() public method

Set the field values. Optionally, you can apply filters to the passed values via callbacks and their parameters
public setFieldValues ( array $values = null, array $filters = null ) : Form
$values array
$filters array
return Form

setFields() public method

Set the fields of the form object.
public setFields ( array $fields ) : Form
$fields array
return Form

setMethod() public method

Set the form method.
public setMethod ( string $method ) : Form
$method string
return Form

setTemplate() public method

Set a form template for the render method to utilize.
public setTemplate ( string $tmpl ) : Form
$tmpl string
return Form

Property Details

$action protected property

Form action
protected string $action
return string

$errorDisplay protected property

Global Form error display format
protected array $errorDisplay
return array

$fields protected property

Form field values
protected array $fields
return array

$form protected property

Form element node
protected Child,Pop\Dom $form
return Pop\Dom\Child

$groups protected property

Form field groups
protected array $groups
return array

$hasFile protected property

Has file flag
protected bool $hasFile
return boolean

$initFieldsValues protected property

Form init field values
protected array $initFieldsValues
return array

$method protected property

Form method
protected string $method
return string

$template protected property

Form template for HTML formatting.
protected string $template
return string