PhpToolCase
Api Documentation Version 0.9.2
PtcForm Class Reference

Public Member Functions

 getOption ($name=null)
 Alias of PtcForm::getOptions( ) More...
 
 __construct ($options=array())
 Sets form method(POST/GET) and retrieves sent values. More...
 
 addElement ($params)
 Adds elemtns to the form object. More...
 
 addSpacer ($spacerVal=null)
 Adds a spacer div. More...
 
 render ($attributes=array(), $events=array())
 Renders the form. More...
 
 validate ()
 Validates form fields defined with the "validate" parameter. More...
 
 validateRequired ($fieldName, $array)
 Checks if value is empty. More...
 
 validateEmail ($fieldName, $array)
 Checks if value is valid email. More...
 
 validateNumber ($fieldName, $array)
 Checks if value is numeric. More...
 
 validateEqualTo ($fieldName, $matchField, $array)
 Checks if value matches other field value. More...
 
 validatePattern ($fieldName, $pattern, $array)
 Checks if given regex pattern is matched. More...
 
 customTpl ($templates)
 Alias of PtcForm::customTpls( ) More...
 
 customTpls ($templates)
 Manipulates html templates for all elements. More...
 
 addElAttribute ($attributes)
 Alias of PtcForm::addElAttributes( ) More...
 
 addElAttributes ($attributes)
 Adds attributes to array of attributes for html elements. More...
 
 setLabelStyle ($labelStyle, $num, $type=null)
 Changes label containers default styles. More...
 
 setInputStyle ($style, $type)
 Changes default input fields style. More...
 
 observe ($class=null)
 Adds observers to manage form events with the PtcEvent component. More...
 
 getOptions ($name=null)
 Returns options defined for the form. More...
 
 setErrorMsg ($msg)
 Adds html before the form container, doesn't have to be an error msg. More...
 

Protected Member Functions

 _addFieldValues ($fieldName, $options)
 Adds values to fields. More...
 
 _removeField ($fieldName)
 Removes a field from the object. More...
 
 _buildContainer ($fieldName, $fieldHtml, $labelHtml= '', $switch=false)
 Builds the container for the field. More...
 
 _addCompositeField ($fieldName, $values)
 Add composite for multiple layouts with html table. More...
 
 _addDefaultValues ($array)
 Adds empty default values when addElement() is called. More...
 
 _switchLabelEl ($fieldName, $labelText)
 Switches between span and label elements according to field type. More...
 
 _buildField ($fieldName)
 Builds the fields. More...
 
 _buildTableData ($cols, $type, $fieldName, $data, $container)
 Builds a dynamic table for multiple layouts. More...
 
 _addFieldParams ($fieldName, $type, $options)
 Adds parameters to the fields. More...
 
 _addValidator ($fieldName, $options)
 Adds validation to the input field. More...
 
 _addClassValidator ($fieldName, $options, $fieldType= 'default')
 Adds validator classes to the fields for js validation. More...
 
 _addInputStyle ($fieldName, $fieldStyle)
 Adds default styles to fields to align properly. More...
 
 _addLabelStyle ($fieldName, $labelContainer, $style)
 Adds default style to the label container to align properly. More...
 
 _addTableStyle ($fieldName, $tableStyle)
 Adds default style to the table to align properly. More...
 
 _buildElAttributes ($container)
 Compiles PtcForm::_elAttributes with the template {attributes}. More...
 
 _buildAttributes ($fieldName, $container, $arrKey)
 Builds attributes for html elements. More...
 
 _addElementId ($fieldName, $arrKey)
 Adds an id to all html elements. More...
 
 _buildList ($fieldName)
 Builds html select options. More...
 
 _buildHtml ($fieldName)
 Builds container for the field. More...
 
 _rebuildValues ($fieldName)
 Rebuilds values for the fields if form has been sent. More...
 
 _buildLabel ($case, $alignLabel, $labelWidth, $labelHtml)
 Builds the label for field. More...
 
 _checkErrors ($fieldName, $type, $function=null, $errType=null)
 Checks for errors while building and rendering the form. More...
 
 _getFormValues ()
 Retrieves form values from POST or GET. More...
 
 _editFormValues ($array)
 Manipulates form values from POST or GET. More...
 
 _randomId ()
 Increases number of random generated id for elements. More...
 
 _fireEvent ($event, $data)
 Fires events with the event class. More...
 
 _getEventClass ()
 Returns the event component name. More...
 

Static Protected Member Functions

static _debug ($string, $statement=null, $category=null)
 Send messsages to the PtcDebug class if present. More...
 

Protected Attributes

 $_errMsg = null
 Property for the message to show on top of the form. More...
 
 $_options = array( )
 Class options property, to be merged with PtcForm::$_defaultOptions property. More...
 
 $_defaultOptions
 Default options for the class. More...
 
 $_htmlTpls
 Html templates property for all elements. More...
 
 $_labelStyles
 Default label styles property. More...
 
 $_inputStyles
 Default input styles options property. More...
 
 $_elAttributes
 Html attributes for all elements. More...
 
 $_storageKeys = array( 'events' , 'attributes' , 'validate' , 'label' , 'labelOptions' , 'parentEl' )
 Possible options in fields storage. More...
 
 $_fields = array( )
 Fields storage property. More...
 
 $_hiddenValues = array( )
 Auto generated hidden fields storage. More...
 
 $_buildHidden = true
 Build hidden values property. More...
 
 $_validate = array( )
 Array of fields to validate with the validator engine. More...
 
 $_observers = array( )
 Observers property. More...
 
 $_events
 Class events property. More...
 
 $_submit = array( )
 Property that holds the submit buttons names. More...
 

Constructor & Destructor Documentation

__construct (   $options = array( ))

Sets form method(POST/GET) and retrieves sent values.

See Class Options

Parameters
array$optionssee PtcForm::$_defaultOptions for available options

Definition at line 24 of file PtcForm.php.

Member Function Documentation

_addClassValidator (   $fieldName,
  $options,
  $fieldType = 'default' 
)
protected

Adds validator classes to the fields for js validation.

Parameters
string$fieldNamethe name of the field
array | string$optionsthe options to pass
string$fieldTypeused by checkbox and radio groups only

Definition at line 1052 of file PtcForm.php.

_addCompositeField (   $fieldName,
  $values 
)
protected

Add composite for multiple layouts with html table.

Parameters
string$fieldNamethe name of the input field
array$valuesarray of fields

Definition at line 673 of file PtcForm.php.

_addDefaultValues (   $array)
protected

Adds empty default values when addElement() is called.

Parameters
string$arraytne field array to add default values to

Definition at line 691 of file PtcForm.php.

_addElementId (   $fieldName,
  $arrKey 
)
protected

Adds an id to all html elements.

Parameters
string$fieldNamethe name of element
string$arrKeythe key inside the PtcForm::$_fields array

Definition at line 1190 of file PtcForm.php.

_addFieldParams (   $fieldName,
  $type,
  $options 
)
protected

Adds parameters to the fields.

Parameters
string$fieldNamethe name of the field
array$type('events','attributes','validate','label','labelOptions','parentEl','value/s')
array | string$optionsthe options to pass

Definition at line 929 of file PtcForm.php.

_addFieldValues (   $fieldName,
  $options 
)
protected

Adds values to fields.

Parameters
string$fieldNamethe name of the field
array | string$optionsvalue/s to add

Definition at line 608 of file PtcForm.php.

_addInputStyle (   $fieldName,
  $fieldStyle 
)
protected

Adds default styles to fields to align properly.

Parameters
string$fieldNamethe name of the field
string$fieldStylethe style property

Definition at line 1081 of file PtcForm.php.

_addLabelStyle (   $fieldName,
  $labelContainer,
  $style 
)
protected

Adds default style to the label container to align properly.

Parameters
string$fieldNamethe name of the field
string$labelContainerthe html template for label element
string$stylethe style property

Definition at line 1099 of file PtcForm.php.

_addTableStyle (   $fieldName,
  $tableStyle 
)
protected

Adds default style to the table to align properly.

Parameters
string$fieldNamethe name of the field
string$tableStylethe style property

Definition at line 1118 of file PtcForm.php.

_addValidator (   $fieldName,
  $options 
)
protected

Adds validation to the input field.

Parameters
string$fieldNamethe name of the field
array | string$optionsthe options to pass

Definition at line 1029 of file PtcForm.php.

_buildAttributes (   $fieldName,
  $container,
  $arrKey 
)
protected

Builds attributes for html elements.

Parameters
string$fieldNamethe name of the field
string$containerthe html template for container
string$arrKey(events,attributes,validate,label,labelOptions,parentEl)

Definition at line 1157 of file PtcForm.php.

_buildContainer (   $fieldName,
  $fieldHtml,
  $labelHtml = '',
  $switch = false 
)
protected

Builds the container for the field.

Parameters
string$fieldNamethe name of the field
string$fieldHtmlthe html field element
string$labelHtmlthe html label element
bool$switchreverse html label position(for radio/checkbox)

Definition at line 654 of file PtcForm.php.

_buildElAttributes (   $container)
protected

Compiles PtcForm::_elAttributes with the template {attributes}.

Parameters
string$containerthe html element

Definition at line 1144 of file PtcForm.php.

_buildField (   $fieldName)
protected

Builds the fields.

Parameters
string$fieldNamethe name of the field

Definition at line 727 of file PtcForm.php.

_buildHtml (   $fieldName)
protected

Builds container for the field.

Parameters
string$fieldNamethe name of the field

Definition at line 1235 of file PtcForm.php.

_buildLabel (   $case,
  $alignLabel,
  $labelWidth,
  $labelHtml 
)
protected

Builds the label for field.

Parameters
string$case(1,2,3)
string$alignLabel("left","top","right","none")
string$labelWidththe width of the label as a percentage
string$labelHtmlthe html template

Definition at line 1336 of file PtcForm.php.

_buildList (   $fieldName)
protected

Builds html select options.

Parameters
string$fieldNamethe name of the select field

Definition at line 1205 of file PtcForm.php.

_buildTableData (   $cols,
  $type,
  $fieldName,
  $data,
  $container 
)
protected

Builds a dynamic table for multiple layouts.

Parameters
string$colsnumber of columns
string$typethe table type(1,2)
string$fieldNamethe name of the field
array$datathe values for the table
string$containerthe html table template

Definition at line 856 of file PtcForm.php.

_checkErrors (   $fieldName,
  $type,
  $function = null,
  $errType = null 
)
protected

Checks for errors while building and rendering the form.

Parameters
string$fieldNamethe name of the field
string$typethe check type (1,2,3,4,5)
string$functionwhich function called this process
string$errTypethe error type

Definition at line 1450 of file PtcForm.php.

static _debug (   $string,
  $statement = null,
  $category = null 
)
staticprotected

Send messsages to the PtcDebug class if present.

Parameters
mixed$stringthe string to pass
mixed$statementsome statement if required
string$categorya category for the messages panel

Definition at line 1563 of file PtcForm.php.

_editFormValues (   $array)
protected

Manipulates form values from POST or GET.

Parameters
array$arrayarray of values(POST or GET)

Definition at line 1515 of file PtcForm.php.

_fireEvent (   $event,
  $data 
)
protected

Fires events with the event class.

Parameters
string$eventthe name of the event
mixed$datathe data to push

Definition at line 1535 of file PtcForm.php.

_getEventClass ( )
protected

Returns the event component name.

Definition at line 1553 of file PtcForm.php.

_getFormValues ( )
protected

Retrieves form values from POST or GET.

Definition at line 1503 of file PtcForm.php.

_randomId ( )
protected

Increases number of random generated id for elements.

Definition at line 1526 of file PtcForm.php.

_rebuildValues (   $fieldName)
protected

Rebuilds values for the fields if form has been sent.

Parameters
string$fieldNamethe name of the field

Definition at line 1275 of file PtcForm.php.

_removeField (   $fieldName)
protected

Removes a field from the object.

Parameters
string$fieldNamethe name of the field to be removed

Definition at line 646 of file PtcForm.php.

_switchLabelEl (   $fieldName,
  $labelText 
)
protected

Switches between span and label elements according to field type.

Parameters
string$fieldNamethe name of the input field
string$labelTextthe text for the label

Definition at line 704 of file PtcForm.php.

addElAttribute (   $attributes)

Alias of PtcForm::addElAttributes( )

Definition at line 404 of file PtcForm.php.

addElAttributes (   $attributes)

Adds attributes to array of attributes for html elements.

See Adding Html Attributes To Elements

Parameters
array | string$attributesarray or string to add as attribute/s

Definition at line 409 of file PtcForm.php.

addElement (   $params)

Adds elemtns to the form object.

See Adding Fields Examples

Parameters
array$paramsparameters for the field, see Field Parameters

Definition at line 74 of file PtcForm.php.

addSpacer (   $spacerVal = null)

Adds a spacer div.

See Adding Custom Fields

Parameters
string$spacerValthe height for the spacer in px
Returns
the output html

Definition at line 164 of file PtcForm.php.

customTpl (   $templates)

Alias of PtcForm::customTpls( )

Definition at line 392 of file PtcForm.php.

customTpls (   $templates)

Manipulates html templates for all elements.

See Manipulating Html Templates

Parameters
array$templatesarray of html templates

Definition at line 397 of file PtcForm.php.

getOption (   $name = null)

Alias of PtcForm::getOptions( )

Parameters
string$namethe name of the option

Definition at line 19 of file PtcForm.php.

getOptions (   $name = null)

Returns options defined for the form.

Parameters
string$namethe option name

Definition at line 470 of file PtcForm.php.

observe (   $class = null)

Adds observers to manage form events with the PtcEvent component.

See Using Observer Events

Parameters
string$classthe name of the observer class

Definition at line 447 of file PtcForm.php.

render (   $attributes = array( ),
  $events = array( ) 
)

Renders the form.

See Rendering The Form

Parameters
array$attributesform attributes
array$eventsform events
Returns
the html will be returned if the option "print_form" is set to false, see PtcForm::$_defaultOptions

Definition at line 176 of file PtcForm.php.

setErrorMsg (   $msg)

Adds html before the form container, doesn't have to be an error msg.

Parameters
string$msgsome text

Definition at line 478 of file PtcForm.php.

setInputStyle (   $style,
  $type 
)

Changes default input fields style.

See Changing default styles for fields

Parameters
array$styleex: "array('border'=>'2px inset','padding'=>'5px');"
string$type"input", "radio" or "button"

Definition at line 435 of file PtcForm.php.

setLabelStyle (   $labelStyle,
  $num,
  $type = null 
)

Changes label containers default styles.

See Changing Default Styles For Label Containers

Parameters
array$labelStyleex: "array('float'=>'left','margin'=>'2px 3px 0 0');"
int$numoptions(1,2,3)
string$type"left","right","top"

Definition at line 420 of file PtcForm.php.

validate ( )

Validates form fields defined with the "validate" parameter.

See Validating The Form (Server Side)

Returns
the validation results, isValid(bool) and errors(array) as array keys

Definition at line 233 of file PtcForm.php.

validateEmail (   $fieldName,
  $array 
)

Checks if value is valid email.

Parameters
string$fieldNamethe name of the input field
array$arrayarray of values to check
Returns
true if value is a correct email, otherwise false

Definition at line 335 of file PtcForm.php.

validateEqualTo (   $fieldName,
  $matchField,
  $array 
)

Checks if value matches other field value.

Parameters
string$fieldNamethe name of the input field
string$matchFieldthe name of the input field to match
array$arrayarray of values to check
Returns
true if value is equal to other given value, otherwise false

Definition at line 366 of file PtcForm.php.

validateNumber (   $fieldName,
  $array 
)

Checks if value is numeric.

Parameters
string$fieldNamethe name of the input field
array$arrayarray of values to check
Returns
true if value is numeric, otherwise false

Definition at line 351 of file PtcForm.php.

validatePattern (   $fieldName,
  $pattern,
  $array 
)

Checks if given regex pattern is matched.

Parameters
string$fieldNamethe name of the input field
string$patternthe pattern to match(regex)
array$arrayarray of values to check
Returns
true if value matches the given pattern, otherwise false

Definition at line 381 of file PtcForm.php.

validateRequired (   $fieldName,
  $array 
)

Checks if value is empty.

Parameters
string$fieldNamethe name of the input field
array$arrayarray of values to check
Returns
true if value is not empty, otherwise false

Definition at line 325 of file PtcForm.php.

Field Documentation

$_buildHidden = true
protected

Build hidden values property.

Definition at line 582 of file PtcForm.php.

$_defaultOptions
protected
Initial value:
= array
(
'form_method' => 'post' ,
'form_action' => '#' ,
'form_width' => '500px' ,
'add_class_validator' => false ,
'labels_align' => 'left' ,
'labels_width' => '40%' ,
'style_elements' => true ,
'style_labels' => true ,
'style_tables' => true ,
'spacer_height' => '3px' ,
'keep_values' => true ,
'print_form' => true ,
'start_tab' => "\t" ,
'err_msg_level' => E_USER_WARNING ,
'debug_category' => 'PtcForm' ,
'event_class' => '\PtcEvent'
)

Default options for the class.

Definition at line 490 of file PtcForm.php.

$_elAttributes
protected
Initial value:
= array
(
'class' , 'id' , 'style' , 'value' , 'maxlength' , 'minlength' ,'cellpadding' ,
'cellspacing' , 'size' , 'disabled' , 'checked' , 'target' , 'align' , 'events' ,
'title' , 'selected' , 'cols' , 'rows' , 'equalTo' , 'border' , 'pattern'
)

Html attributes for all elements.

Definition at line 561 of file PtcForm.php.

$_errMsg = null
protected

Property for the message to show on top of the form.

Definition at line 482 of file PtcForm.php.

$_events
protected
Initial value:
= array
(
'rendering' , 'rendered' , 'validating' , 'validated' ,
'building' , 'built' , 'error' , 'valid' , 'submit' , 'adding' , 'added'
)

Class events property.

Definition at line 594 of file PtcForm.php.

$_fields = array( )
protected

Fields storage property.

Definition at line 574 of file PtcForm.php.

$_hiddenValues = array( )
protected

Auto generated hidden fields storage.

Definition at line 578 of file PtcForm.php.

$_htmlTpls
protected
Initial value:
= array
(
'select_option' => '<option {attributes}>{label}</option>',
'select' => '<select name="{name}" {attributes}>{options}</select>',
'textarea' => '<textarea name="{name}" {attributes}>{value}</textarea>',
'input' => '<input type="{type}" name="{name}" {attributes}>',
'fieldset' => '<fieldset {attributes}>{label}{data} {start_tab}</fieldset>',
'form' => '<form {method} {action} {attributes}>{fields}</form>',
'spacer' => '<div style="clear:both;height:{spacerVal}" {id}><!-- --></div>',
'label' => '<label {for} {attributes}>{label}</label>',
'legend' => '<legend {attributes}>{label}</legend>',
'span' => '<span {attributes}>{label}</span>',
'td' => '<td align="left" valign="top">',
'table' => '<table {attributes}>',
'field_container' => '<div {attributes}>{label}{field} {start_tab}</div>',
'main_container' => '<div style="width:{form_width}">{form}</div>'
)

Html templates property for all elements.

Definition at line 512 of file PtcForm.php.

$_inputStyles
protected
Initial value:
=array
(
'radio' => array( 'padding' => '0px' , 'margin' => '0px' , 'vertical-align' => 'middle' , 'width' => '14px' ) ,
'input' => array( 'margin' => '0px' , 'padding' => '3px' , 'border' => '1px inset' ) ,
'button' => array( 'margin' => '0px' )
)

Default input styles options property.

Definition at line 552 of file PtcForm.php.

$_labelStyles
protected
Initial value:
= array
(
1 => array( 'left' => array( 'float' => 'left' , 'margin' => '2px 0 0 0' , 'width' => '{label_width}%' ) ,
'right' => array( 'float' => 'left' , 'margin' => '1px 3px 0 0' ,
'text-align' => 'right' , 'width' => '{label_width}%' ) ,
'top' => array( ) ) ,
2 => array( 'left' => array( 'vertical-align' => 'middle' , 'border' => 'none' ) ,
'right' => array( 'vertical-align' => 'middle' , 'border' => 'none' ) ,
'top' => array( ) ) ,
3 => array( 'left' => array( 'float' => 'left' , 'margin' => '3px 0 0 0' , 'width' => '{label_width}%' ) ,
'right' => array( 'float' => 'left' , 'margin' => '1px 3px 0 0' ,
'text-align' => 'right' , 'width' => '{label_width}%' ) ,
'top' => array( ) )
)

Default label styles property.

Definition at line 532 of file PtcForm.php.

$_observers = array( )
protected

Observers property.

Definition at line 590 of file PtcForm.php.

$_options = array( )
protected

Class options property, to be merged with PtcForm::$_defaultOptions property.

Definition at line 486 of file PtcForm.php.

$_storageKeys = array( 'events' , 'attributes' , 'validate' , 'label' , 'labelOptions' , 'parentEl' )
protected

Possible options in fields storage.

Definition at line 570 of file PtcForm.php.

$_submit = array( )
protected

Property that holds the submit buttons names.

Definition at line 602 of file PtcForm.php.

$_validate = array( )
protected

Array of fields to validate with the validator engine.

Definition at line 586 of file PtcForm.php.


The documentation for this class was generated from the following file: