Topics

Class Field

Web page form field

Namespace: Ip\Form

Constants:

string LAYOUT_DEFAULT 'default'
string LAYOUT_BLANK 'blank'
string LAYOUT_NO_LABEL 'noLabel'
string TYPE_REGULAR 'regular'
string TYPE_SYSTEM 'system'

Methods:

__construct( [ array $options = array() ] )

Constructor

Parameters:

array $options
string render( string $doctype , string $environment )

Render field's HTML code

Parameters:

string $doctype \Ip\View doctype constant
string $environment \Ip\Form::ENVIRONMENT_ADMIN or \Ip\Form::ENVIRONMENT_PUBLIC

Return values:

string
string getLayout( )

Get field layout

Return values:

string
string getType( )

Get field type

Return values:

string
string getAttributesStr( string $doctype )

Get field attributes as HTML string

Parameters:

string $doctype \Ip\View doctype constant

Return values:

string
string getValueAsString( array $values , string $valueKey )

Get a value from posted form values array

Parameters:

array $values All posted form values.
string $valueKey This field name.

Return values:

string
Ip\Form\Validator[] getValidators( )

Get validators

Return values:

Ip\Form\Validator[]
boolean isRequired( )

Check if the field is required

Return values:

boolean
boolean validate( string $values , string $valueKey , string $environment )

Check if field passes validation

Parameters:

string $values
string $valueKey
string $environment \Ip\Form::ENVIRONMENT_ADMIN or \Ip\Form::ENVIRONMENT_PUBLIC

Return values:

boolean
addValidator( mixed $validator )

Add a validator to a field

Available validators are located at Ip/Form/Field/Validator folder. E.g., to add required field validator use $field->addValidator('Required') method.

Parameters:

mixed $validator

Throws:

Ip\Exception
removeValidator( mixed $validator )

Remove field validator

Parameters:

mixed $validator
addAttribute( string $name , string $value )

Add HTML attribute to input field

Alternative way to setAttributes method.

Parameters:

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

Remove HTML attribute

Parameters:

mixed $name
string getValidationAttributesStr( string $doctype )

Get validator HTML attributes

Needed for JavaScript validator.

Parameters:

string $doctype \Ip\View doctype constant.

Return values:

string
string getTypeClass( )

CSS class that should be applied to surrounding element of this field. By default empty. Extending classes should specify their constant value. This field is not used to identify fields by their type. So each extending class should return its own unique and constant string.

Return values:

string
string getLabel( )

Get field label

Return values:

string Field label
setLabel( string $label )

Set field label

Parameters:

string $label
string getHint( )

Get field input hint text

Return values:

string Hint
setHint( string $hint )

Set field input hint text

Parameters:

string $hint Hint
string getNote( )

Get field note text

Return values:

string Text note.
setNote( string $note )

Set field note text

Parameters:

string $note Note text.
string getName( )

Get field name attribute

Return values:

string Field name.
string getValidationInputName( )

If your input has many input fields

Eg. field[id], field[code], ... Return the name of input that should hold error message.

Return values:

string
setName( string $name )

Set field name attribute

Parameters:

string $name Field name.
mixed getValue( )

Get field value

Return values:

mixed Field value.
setValue( string $value )

Set field value

Parameters:

string $value Field value.
setLayout( string $layout )

Set field layout. Use constants \Ip\Form\Field::LAYOUT_DEFAULT, \Ip\Form\Field::LAYOUT_BLANK, \Ip\Form\Field::LAYOUT_NO_LABEL,

Parameters:

string $layout.
array getAttributes( )

Get all HTML attributes of the field

Return values:

array Field HTML attributes.
string|boolean getAttribute( string $attribute )

Get specific HTML attribute of the field

Parameters:

string $attribute

Return values:

string|boolean
setAttributes( array $attributes )

Set extra HTML attributes from associative array

Does not affect default class, name, required, type and value attributes.

Parameters:

array $attributes Associative array with keys as attribute names and values as attribute values.
string getId( )

Get field "id" HTML attribute

Return values:

string HTML "id" attribute value
addClass( string $cssClass )

Add CSS class to form field

Parameters:

string $cssClass
removeClass( mixed $cssClass )

Remove CSS class from a form field

Parameters:

mixed $cssClass
array getClasses( )

Get a list of field's HTML classes

Return values:

array
string getClassesStr( )

Get class attributes as a string

Return values:

string
setCssClasses( mixed $classes )

Set css class

comments powered by Disqus