Topics

Class Form

Handles web page forms

Namespace: Ip

Constants:

string METHOD_POST 'post'
string METHOD_GET 'get'
string ENVIRONMENT_ADMIN 'admin'
string ENVIRONMENT_PUBLIC 'public'

Methods:

__construct( )
addSpamCheck( )

Add securityToken field

removeSpamCheck( )

Remove securityToken field

setEnvironment( mixed $environment )

Set form environment. Depending on that public or admin translations and layout will be chosen. ImpressPages tries to detect environment automatically based on current controller. You can set manually the right mode if needed.

Parameters:

mixed $environment
mixed getEnvironment( )

Get form environment. Depending on that public or admin translations and layout will be chosen.

Return values:

mixed
addCsrfCheck( )

Add securityToken field

removeCsrfCheck( )

Remove securityToken field

integer removeField( string $fieldName )

Remove field from fieldset

Parameters:

string $fieldName

Return values:

integer Removed fields count
array validate( array $data )

Check if data passes form validation rules

Parameters:

array $data - post data from user or other source.

Return values:

array Error list. Array key - error field name, value - error message. Empty array means no errors.
array filterValues( array $data )

Filter data array. Return only those records that are expected according to form field names.

Parameters:

array $data

Return values:

array
addFieldset( Ip\Form\Fieldset $fieldset )

Add a fieldset to a form

Parameters:

Ip\Form\Fieldset | string $fieldset
addField( Ip\Form\Field $field )

Add field to last fieldset. Create fieldset if does not exist.

Parameters:

Ip\Form\Field $field
setMethod( string $method )

Set post method.

Parameters:

string $method Use \Ip\Form::METHOD_POST or \Ip\Form::METHOD_GET

Throws:

Ip\Exception
string getMethod( )

Get HTML form method attribute value

Return values:

string
setAction( string $action )

Set HTML form action attribute

Parameters:

string $action
string getAction( )

Get HTML form action attribute

Return values:

string Attribute
string render( [ Ip\View $view = null ] )

Get rendered form

Parameters:

Ip\View $view

Return values:

string HTML form
array|Ip\Form\Fieldset[] getFieldsets( )

Return all fieldsets

Return values:

array|Ip\Form\Fieldset[]
Ip\Form\Field[] getFields( )

Get all form fields

Return values:

Ip\Form\Field[]
Ip\Form\Field getField( mixed $name )

Get form field

Parameters:

mixed $name

Return values:

Ip\Form\Field
addAttribute( string $name , string $value )

Add HTML attribute to the form

Parameters:

string $name Attribute name
string $value Attribute value
removeAttribute( string $name )

Remove HTML attribute from the form

Parameters:

string $name
array getAttributes( )

Get all form attributes

Return values:

array
string getAttributesStr( )

Get all form attributes as HTML

Return values:

string Attributes, provided in attribute="value" style
addClass( string $cssClass )

Add CSS class to the form

Parameters:

string $cssClass
removeClass( string $cssClass )

Remove CSS class from the form

Parameters:

string $cssClass
array getClasses( )

Get a list of classes used in the form

Return values:

array An array containing class names
string getClassesStr( )

Get a list of classes used in the form as HTML string

Return values:

string Attributes, provided in attribute="value" style
setAjaxSubmit( mixed $ajaxSubmit )

Set ajaxSubmit attribute. If true, form will be automatically

Parameters:

mixed $ajaxSubmit
boolean getAjaxSubmit( )

Get ajaxSubmit property

Return values:

boolean
setValidate( mixed $validate )

Set validate attribute. If true, form will be automatically validated by javascript on submit

Parameters:

mixed $validate
boolean getValidate( mixed $validate )

Get validate property

Parameters:

mixed $validate

Return values:

boolean
comments powered by Disqus