PhpToolCase
[ class tree: PhpToolCase ] [ index: PhpToolCase ] [ all elements ]

Class: PtcForms

Source Location: /workshop/PhpToolCase/current/PtcForms.php

Class PtcForms

Property Summary
bool   $_buildHidden   Build hidden values property
array   $_defaultOptions   Default options for the class
array   $_elAttributes   Html attributes for all elements
array   $_fields   Fields storage property
array   $_hiddenValues   Auto generated hidden fields storage
array   $_htmlTpls   Html templates property for all elements
array   $_inputStyles   Default input styles options property
array   $_labelStyles   Default label styles property
array   $_options   Class options property, to be merged with $_defaultOptions property
array   $_storageKeys   Possible options in fields storage
array   $_validate   Array of fields to validate with the validator engine

[ Top ]
Method Summary
PtcForms   __construct()   Sets form method(POST/GET) and retrieves sent values
void   addElAttribute()   Alias of addElAttributes()
void   addElAttributes()   Adds attributes to array of attributes for html elements
void   addElement()   Adds a field to the form object
returns   addSpacer()   Adds a spacer div
void   customTpl()   Alias of customTpls()
void   customTpls()   Manipulates html templates for all elements
the   render()   Renders the form
void   setInputStyle()   Changes default input fields style
void   setLabelStyle()   Changes label containers default styles
returns   validate()   Validate form fields defined with the "validate" parameter
returns   validateEmail()   Check if value is valid email
returns   validateEqualTo()   Check if value matches other field value
returns   validateNumber()   Check if value is numeric
returns   validatePattern()   Check if given regex pattern is matched
returns   validateRequired()   Check if value is empty
void   _addClassValidator()   Adds validator classes to the fields for js validation
void   _addCompositeField()   Add composite for multiple layouts with html table
void   _addDefaultValues()   Adds empty default values when addElement() is called
void   _addElementId()   Adds an id to all html elements
void   _addFieldParams()   Adds parameters to the fields
void   _addFieldValues()   Adds values to fields
void   _addInputStyle()   Adds default styles to fields to align properly
void   _addLabelStyle()   Adds default style to the label container to align properly
void   _addTableStyle()   Adds default style to the table to align properly
void   _addValidator()   Adds validation to the input field
void   _buildAttributes()   Builds attributes for html elements
void   _buildContainer()   Builds the container for the field
void   _buildElAttributes()   Compiles _elAttributes with the template {attributes}
void   _buildField()   Builds the fields
void   _buildHtml()   Builds container for the field
void   _buildLabel()   Builds the label for field
void   _buildList()   Builds html select options
void   _buildTableData()   Builds a dynamic table for multiple layouts
void   _checkErrors()   Checks for errors while building and rendering the form
void   _editFormValues()   Manipulates form values from POST or GET
void   _getFormValues()   Retrieves form values from POST or GET
void   _randomId()   Increases number of random generated id for elements
void   _rebuildValues()   Rebuilds values for the fields if form has been sent
void   _removeField()   Removes a field from the object
void   _switchLabelEl()   Switches between span and label elements according to field type

[ Top ]
Properties
bool   $_buildHidden = true [line 1319]

Build hidden values property

API Tags:
Access:  private


[ Top ]
array   $_defaultOptions = array
(
'form_method' => 'post', // the form method to use
'form_action' => '#', // the form action url
'form_width' => '500px', // the width for the main container
'add_class_validator' => false, // add validator classes to fields for use with jquery
'labels_align' => 'left', // align labels globally(left,top,right,none)
'labels_width' => '40%', // the width for labels as a percentage
'style_elements' => true, // add default style to input elements to align properly
'style_labels' => true, // add default style to label elements to align properly
'style_tables' => true, // add default style to table elements to align properly
'spacer_height' => '3px', // height for the spacer between fields
'keep_values' => true, // repopulate filled fields on form submission
'print_form' => true, // print form to screen or return html only
'start_tab' => "\t", // format html code with tabs
'err_msg_level' => E_USER_WARNING, // error messages level
'debug_category' => 'PtcForms' // default category for the PtcDebug class
)
[line 350]

Default options for the class

API Tags:
Access:  protected

Information Tags:
Tutorial:  CLASS OPTIONS

[ Top ]
array   $_elAttributes = array('class','id','style','value','maxlength','size','disabled','checked','target','align',
'events','title','selected','cols','rows','equalTo','border','pattern','cellpadding','cellspacing')
[line 428]

Html attributes for all elements

API Tags:
Access:  protected

Information Tags:
Tutorial:  ADDING HTML ATTRIBUTES TO ELEMENTS

[ Top ]
array   $_fields = array() [line 439]

Fields storage property

API Tags:
Access:  protected


[ Top ]
array   $_hiddenValues = array() [line 444]

Auto generated hidden fields storage

API Tags:
Access:  protected


[ Top ]
array   $_htmlTpls = 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>'
)
[line 373]

Html templates property for all elements

API Tags:
Access:  protected

Information Tags:
Tutorial:  MANIPULATING HTML TEMPLATES

[ Top ]
array   $_inputStyles = array
(
'radio' => array('padding'=>'0px','margin'=>'0px','vertical-align'=>'middle','width'=>'14px'),'input'=>array('margin'=>'0px','padding'=>'3px','border'=>'1px inset'),//padding:2px;
'button'=>array('margin'=>'0px'))
[line 417]

Default input styles options property

API Tags:
Access:  protected

Information Tags:
Tutorial:  Changing default styles for fields

[ Top ]
array   $_labelStyles = array
(
/* Styles for input, select and textarea */
1 => array('left'=>array('float'=>'left','margin'=>'2px 0 0 0','width'=>'{label_width}%'),//margin:1px 0 0 0
'right'=>array('float'=>'left','margin'=>'1px 3px 0 0',//margin:0 3px 0 0;
'text-align'=>'right','width'=>'{label_width}%'),'top'=>array()),/* Styles for checkbox and radio buttons */2=>array('left'=>array('vertical-align'=>'middle','border'=>'none'),'right'=>array('vertical-align'=>'middle','border'=>'none'),'top'=>array()),/* Styles for radio/checkbox group and composite fields */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()))
[line 395]

Default label styles property

API Tags:
Access:  protected

Information Tags:
Tutorial:  Changing default styles for label containers

[ Top ]
array   $_options = array() [line 344]

Class options property, to be merged with $_defaultOptions property

API Tags:
See:  PtcForms::$_defaultOptions
Access:  protected


[ Top ]
array   $_storageKeys = array('events','attributes','validate','label','labelOptions','parentEl') [line 434]

Possible options in fields storage

API Tags:
Access:  protected


[ Top ]
array   $_validate = array() [line 450]

Array of fields to validate with the validator engine

API Tags:
Access:  protected

Information Tags:
Tutorial:  ADDING AND VALIDATING FIELDS WITH THE VALIDATOR ENGINE

[ Top ]
Methods
Constructor __construct  [line 19]

  PtcForms __construct( [array $options = null]  )

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

Parameters:
array   $options:  see _defaultOptions for available options

API Tags:
Access:  public

Information Tags:
Tutorial:  CLASS OPTIONS

[ Top ]
addElAttribute  [line 306]

  void addElAttribute( $attributes  )

Alias of addElAttributes()

Parameters:
   $attributes: 

API Tags:
Access:  public


[ Top ]
addElAttributes  [line 313]

  void addElAttributes( array|string $attributes  )

Adds attributes to array of attributes for html elements

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

API Tags:
See:  PtcForms::$_elAttributes
Access:  public

Information Tags:
Tutorial:  Extending the compiler with custom attributes

[ Top ]
addElement  [line 47]

  void addElement( array $params  )

Adds a field to the form object

Parameters:
array   $params:  parameters for the field

API Tags:
See:  PtcForms::$_fields
Access:  public

Information Tags:
Tutorial:  ADDING FIELDS EXAMPLES

[ Top ]
addSpacer  [line 129]

  returns addSpacer( [string $spacerVal = null]  )

Adds a spacer div

Parameters:
string   $spacerVal:  the height for the spacer in px

API Tags:
Return:  the html
Access:  public

Information Tags:
Tutorial:  Adding a Custom Field

[ Top ]
customTpl  [line 292]

  void customTpl( $templates  )

Alias of customTpls()

Parameters:
   $templates: 

API Tags:
Access:  public


[ Top ]
customTpls  [line 299]

  void customTpls( array $templates  )

Manipulates html templates for all elements

Parameters:
array   $templates:  array of html templates

API Tags:
See:  PtcForms::$_htmlTpls
Access:  public

Information Tags:
Tutorial:  MANIPULATING HTML TEMPLATES

[ Top ]
render  [line 142]

  the render( [array $attributes = array()], [array $events = array()]  )

Renders the form

Parameters:
array   $attributes:  form attributes
array   $events:  form events

API Tags:
Return:  html will be returned if the option "print_form" is set to false, see _defaultOptions
Access:  public

Information Tags:
Tutorial:  RENDERING THE FORM

[ Top ]
setInputStyle  [line 338]

  void setInputStyle( array $style, string $type  )

Changes default input fields style

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

API Tags:
See:  PtcForms::$_inputStyles
Access:  public

Information Tags:
Tutorial:  Changing default styles for fields

[ Top ]
setLabelStyle  [line 326]

  void setLabelStyle( array $labelStyle, int $num, [string $type = null]  )

Changes label containers default styles

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

API Tags:
See:  PtcForms::$_labelStyles
Access:  public

Information Tags:
Tutorial:  Changing default styles for label containers

[ Top ]
validate  [line 185]

  returns validate( )

Validate form fields defined with the "validate" parameter


API Tags:
Return:  the validator fields, isValid(bool) and errors(array) as array keys
Access:  public

Information Tags:
Tutorial:  Validating The Form (Server Side)

[ Top ]
validateEmail  [line 255]

  returns validateEmail( string $fieldName, array $array  )

Check if value is valid email

Parameters:
string   $fieldName:  the name of the input field
array   $array:  array of values to check

API Tags:
Return:  true if value is a correct email, otherwise false
Access:  public


[ Top ]
validateEqualTo  [line 274]

  returns validateEqualTo( string $fieldName, string $matchField, array $array  )

Check if value matches other field value

Parameters:
string   $fieldName:  the name of the input field
string   $matchField:  the name of the input field to match
array   $array:  array of values to check

API Tags:
Return:  true if value is equal to other given value, otherwise false
Access:  public


[ Top ]
validateNumber  [line 266]

  returns validateNumber( string $fieldName, array $array  )

Check if value is numeric

Parameters:
string   $fieldName:  the name of the input field
array   $array:  array of values to check

API Tags:
Return:  true if value is numeric, otherwise false
Access:  public


[ Top ]
validatePattern  [line 285]

  returns validatePattern( string $fieldName, string $pattern, array $array  )

Check if given regex pattern is matched

Parameters:
string   $fieldName:  the name of the input field
string   $pattern:  the pattern to match(regex)
array   $array:  array of values to check

API Tags:
Return:  true if value matches the given pattern, otherwise false
Access:  public


[ Top ]
validateRequired  [line 248]

  returns validateRequired( string $fieldName, array $array  )

Check if value is empty

Parameters:
string   $fieldName:  the name of the input field
array   $array:  array of values to check

API Tags:
Return:  true if value is not empty, otherwise false
Access:  public


[ Top ]
_addClassValidator  [line 889]

  void _addClassValidator( string $fieldName, array|string $options, [string $fieldType = 'default']  )

Adds validator classes to the fields for js validation

Parameters:
string   $fieldName:  the name of the field
array|string   $options:  the options to pass
string   $fieldType:  used by checkbox and radio groups only

API Tags:
Access:  protected


[ Top ]
_addCompositeField  [line 520]

  void _addCompositeField( string $fieldName, array $values  )

Add composite for multiple layouts with html table

Parameters:
string   $fieldName:  the name of the input field
array   $values:  array of fields

API Tags:
Access:  protected


[ Top ]
_addDefaultValues  [line 539]

  void _addDefaultValues( string $array  )

Adds empty default values when addElement() is called

Parameters:
string   $array: 

API Tags:
See:  PtcForms::$_storageKeys
Access:  protected


[ Top ]
_addElementId  [line 1015]

  void _addElementId( string $fieldName, string $arrKey  )

Adds an id to all html elements

Parameters:
string   $fieldName:  the name of element
string   $arrKey:  the key inside the _fields array

API Tags:
Access:  protected


[ Top ]
_addFieldParams  [line 776]

  void _addFieldParams( string $fieldName, array $type, array|string $options  )

Adds parameters to the fields

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

API Tags:
Access:  protected


[ Top ]
_addFieldValues  [line 456]

  void _addFieldValues( string $fieldName, array|string $options  )

Adds values to fields

Parameters:
string   $fieldName:  the name of the field
array|string   $options:  value/s to add

API Tags:
Access:  protected


[ Top ]
_addInputStyle  [line 918]

  void _addInputStyle( string $fieldName, string $fieldStyle  )

Adds default styles to fields to align properly

Parameters:
string   $fieldName:  the name of the field
string   $fieldStyle:  the style property

API Tags:
Access:  protected


[ Top ]
_addLabelStyle  [line 936]

  void _addLabelStyle( string $fieldName, string $labelContainer, string $style  )

Adds default style to the label container to align properly

Parameters:
string   $fieldName:  the name of the field
string   $labelContainer:  the html template for label element
string   $style:  the style property

API Tags:
Access:  protected


[ Top ]
_addTableStyle  [line 951]

  void _addTableStyle( string $fieldName, string $tableStyle  )

Adds default style to the table to align properly

Parameters:
string   $fieldName:  the name of the field
string   $tableStyle:  the style property

API Tags:
Access:  protected


[ Top ]
_addValidator  [line 866]

  void _addValidator( string $fieldName, array|string $options  )

Adds validation to the input field

Parameters:
string   $fieldName:  the name of the field
array|string   $options:  the options to pass

API Tags:
Access:  protected


[ Top ]
_buildAttributes  [line 989]

  void _buildAttributes( string $fieldName, string $container, string $arrKey  )

Builds attributes for html elements

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

API Tags:
Access:  protected


[ Top ]
_buildContainer  [line 501]

  void _buildContainer( string $fieldName, string $fieldHtml, [string $labelHtml = ''], [bool $switch = false]  )

Builds the container for the field

Parameters:
string   $fieldName:  the name of the field
string   $fieldHtml:  the html field element
string   $labelHtml:  the html label element
bool   $switch:  reverse html label position(for radio/checkbox)

API Tags:
Access:  protected


[ Top ]
_buildElAttributes  [line 977]

  void _buildElAttributes( string $container  )

Compiles _elAttributes with the template {attributes}

Parameters:
string   $container:  the html element

API Tags:
Access:  protected


[ Top ]
_buildField  [line 574]

  void _buildField( string $fieldName  )

Builds the fields

Parameters:
string   $fieldName:  the name of the field

API Tags:
Access:  protected


[ Top ]
_buildHtml  [line 1052]

  void _buildHtml( string $fieldName  )

Builds container for the field

Parameters:
string   $fieldName:  the name of the field

API Tags:
Access:  protected


[ Top ]
_buildLabel  [line 1144]

  void _buildLabel( string $case, string $alignLabel, string $labelWidth, string $labelHtml  )

Builds the label for field

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

API Tags:
Access:  protected


[ Top ]
_buildList  [line 1030]

  void _buildList( string $fieldName  )

Builds html select options

Parameters:
string   $fieldName:  the name of the select field

API Tags:
Access:  protected


[ Top ]
_buildTableData  [line 703]

  void _buildTableData( string $cols, string $type, string $fieldName, array $data, string $container  )

Builds a dynamic table for multiple layouts

Parameters:
string   $cols:  number of columns
string   $type:  the table type(1,2)
string   $fieldName:  the name of the field
array   $data:  the values for the table
string   $container:  the html table template

API Tags:
Access:  protected


[ Top ]
_checkErrors  [line 1238]

  void _checkErrors( string $fieldName, string $type, [string $function = null], [string $errType = null]  )

Checks for errors while building and rendering the form

Parameters:
string   $fieldName:  the name of the field
string   $type:  the check type (1,2,3,4,5)
string   $function:  which function called this process
string   $errType:  the error type

API Tags:
Access:  protected


[ Top ]
_editFormValues  [line 1303]

  void _editFormValues( array $array  )

Manipulates form values from POST or GET

Parameters:
array   $array:  array of values(POST or GET)

API Tags:
Access:  protected


[ Top ]
_getFormValues  [line 1291]

  void _getFormValues( )

Retrieves form values from POST or GET


API Tags:
Access:  protected


[ Top ]
_randomId  [line 1314]

  void _randomId( )

Increases number of random generated id for elements


API Tags:
Access:  protected


[ Top ]
_rebuildValues  [line 1089]

  void _rebuildValues( string $fieldName  )

Rebuilds values for the fields if form has been sent

Parameters:
string   $fieldName:  the name of the field

API Tags:
Access:  protected


[ Top ]
_removeField  [line 493]

  void _removeField( string $fieldName  )

Removes a field from the object

Parameters:
string   $fieldName:  the name of the field to be removed

API Tags:
Access:  protected


[ Top ]
_switchLabelEl  [line 552]

  void _switchLabelEl( string $fieldName, string $labelText  )

Switches between span and label elements according to field type

Parameters:
string   $fieldName:  the name of the input field
string   $labelText:  the text for the label

API Tags:
Access:  protected


[ Top ]

Documentation generated on Fri, 30 Aug 2013 15:28:58 +0200 by phpDocumentor 1.4.3