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 parameter
array   $_defaultOptions   default options
array   $_elAttributes   html attributes for all elements
array   $_formFields   fields storage
array   $_hiddenValues   auto generated hidden fields storage
array   $_htmlTpls   html templates
array   $_inputStyles   default Input styles options
mixed   $_labelStyles  
array   $_storageKeys   possible options in fields storage
array   $_validate   array of fields to validate

[ Top ]
Method Summary
PtcForms   __construct()   Sets form method(POST/GET) and retrieves already sent values
void   addElAttribute()   Alias of addElAttributes()
void   addElAttributes()   Add attributes to array of attributes for all html elements used by the class
void   addField()   Add field to the form object
void   addFieldAttributes()   Add attributes to input field
void   addFieldEvent()   Alias of addFieldEvents()
void   addFieldEvents()   Add events to input field
void   addFieldLabel()   Add a label text for the field
void   addFieldValidator()   Add validator for input field
void   addFieldValue()   Alias of addFieldValues()
void   addFieldValues()   Add values to fields
void   addLabelOptions()   Add attributes to the label
void   addSpacer()   Add spacer div
void   addValuesParams()   Add paramaters to field values group
void   customTpl()   Alias of customTpls()
void   customTpls()   Manipulate html templates
void   fieldParentEl()   Add attributes to div container for input field
void   removeField()   Remove field(under development)
void   render()   Render form
void   renderForm()   Alias of render()
void   setInputStyle()   Change default input fields style
void   setLabelStyle()   Change Labels default styles
returns   validate()   Validate form fields defined with the addFieldValidator() method
returns   validateEmail()   Check if value is valid email
returns   validateEqualTo()   Check if value matches other field value
void   validateForm()   Alias of validate()
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()   Add validator classes to field for js validation
void   _addCompositeField()   Add composite for multiple layouts with html table
void   _addDefaultValues()   Add empty default values when addField() is called
void   _addElementId()   Add an id to all html elements
void   _addFieldParams()   Add parameters to field
void   _addInputStyle()   Add default style to field to align properly
void   _addLabelStyle()   Add default style to label to align properly
void   _addTableStyle()   Add default style to table to align properly
void   _addValidator()   Add validator to input field
void   _buildAttributes()   Build attributes for html elements
void   _buildContainer()   Build container for field
void   _buildElAttributes()   Replace $_elAttributes with template {attributes}
void   _buildField()   Build fields
void   _buildHtml()   Build container for field
void   _buildLabel()   Build label for field
void   _buildList()   Build html select options
void   _buildTableData()   Build dynamic table for multiple layouts
void   _checkErrors()   Checks for errors while building and rendering the form
void   _editFormValues()   Manipulate form values from POST or GET
void   _getFormValues()   Retrieve form values from POST or GET
void   _randomId()   Increase number of random generated id for elements
void   _rebuildValues()   Rebuild values for fields if POST or GET
void   _switchLabelEl()   Switch between span and label elements according to field type

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

build hidden values parameter

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)
"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
)
[line 382]

default options

API Tags:
Access:  protected


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

html attributes for all elements

API Tags:
Access:  protected


[ Top ]
array   $_formFields = array() [line 464]

fields storage

API Tags:
Access:  protected


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

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 403]

html templates

API Tags:
Access:  protected


[ 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 443]

default Input styles options

API Tags:
Access:  protected


[ Top ]
mixed   $_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 423]
API Tags:
Access:  protected


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

possible options in fields storage

API Tags:
Access:  protected


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

array of fields to validate

API Tags:
Access:  protected


[ Top ]
Methods
Constructor __construct  [line 18]

  PtcForms __construct( [array $options = null]  )

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

Parameters:
array   $options:  array of options, see _defaultOptions for available options

API Tags:
Access:  public


[ Top ]
addElAttribute  [line 345]

  void addElAttribute( $attributes  )

Alias of addElAttributes()

Parameters:
   $attributes: 

API Tags:
Access:  public


[ Top ]
addElAttributes  [line 352]

  void addElAttributes( array|string $attributes  )

Add attributes to array of attributes for all html elements used by the class

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 ]
addField  [line 46]

  void addField( string $type, string $fieldName  )

Add field to the form object

Parameters:
string   $type:  the field type, view manual for possible values
string   $fieldName:  the name for the input field

API Tags:
Access:  public

Information Tags:
Tutorial:  ADDING FIELDS

[ Top ]
addFieldAttributes  [line 98]

  void addFieldAttributes( string $fieldName, array $options  )

Add attributes to input field

Parameters:
string   $fieldName:  the name of the input field
array   $options:  attributes to add Ex:("class","id","style")

API Tags:
Access:  public

Information Tags:
Tutorial:  Adding attributes to fields

[ Top ]
addFieldEvent  [line 58]

  void addFieldEvent( $fieldName, $options  )

Alias of addFieldEvents()

Parameters:
   $fieldName: 
   $options: 

API Tags:
Access:  public


[ Top ]
addFieldEvents  [line 84]

  void addFieldEvents( string $fieldName, array $options  )

Add events to input field

Parameters:
string   $fieldName:  the name of the input field
array   $options:  javascript events to add to the input field

API Tags:
Access:  public

Information Tags:
Tutorial:  ADDING FIELD EVENTS

[ Top ]
addFieldLabel  [line 70]

  void addFieldLabel( string $fieldName, string $label  )

Add a label text for the field

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

API Tags:
Access:  public

Information Tags:
Tutorial:  ADDING LABELS

[ Top ]
addFieldValidator  [line 91]

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

Add validator for input field

Parameters:
string   $fieldName:  the name of the input field
array|string   $options:  add validator options Ex:("required","email")

API Tags:
Access:  public

Information Tags:
Tutorial:  Adding Fields To The Validator

[ Top ]
addFieldValue  [line 54]

  void addFieldValue( $fieldName, $options  )

Alias of addFieldValues()

Parameters:
   $fieldName: 
   $options: 

API Tags:
Access:  public


[ Top ]
addFieldValues  [line 120]

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

Add values to fields

Parameters:
string   $fieldName:  the name of the input field
array|string   $options:  value/s to add, view manual for possible options

API Tags:
Access:  public

Information Tags:
Tutorial:  ADDING VALUES TO FIELDS

[ Top ]
addLabelOptions  [line 77]

  void addLabelOptions( string $fieldName, array $options  )

Add attributes to the label

Parameters:
string   $fieldName:  the name of the field
array   $options:  attributes to add to the label Ex:("id","class","style")

API Tags:
Access:  public

Information Tags:
Tutorial:  Adding attributes to label container

[ Top ]
addSpacer  [line 173]

  void addSpacer( [string $spacerVal = null]  )

Add spacer div

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

API Tags:
Access:  public

Information Tags:
Tutorial:  Adding a Custom Field for a Spacer

[ Top ]
addValuesParams  [line 159]

  void addValuesParams( string $fieldName, $type, array $options  )

Add paramaters to field values group

Parameters:
string   $fieldName:  the name of the input field
array   $options:  value/s to add, view manual for possible options
   $type: 

API Tags:
Access:  public

Information Tags:
Tutorial:  ADDING PARAMETERS TO VALUES

[ Top ]
customTpl  [line 331]

  void customTpl( $templates  )

Alias of customTpls()

Parameters:
   $templates: 

API Tags:
Access:  public


[ Top ]
customTpls  [line 338]

  void customTpls( array $templates  )

Manipulate html templates

Parameters:
array   $templates:  array of html templates

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

Information Tags:
Tutorial:  MANIPULATING HTML TEMPLATES

[ Top ]
fieldParentEl  [line 105]

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

Add attributes to div container for input field

Parameters:
string   $fieldName:  the name of the input field
array|string   $options:  attributes to add, view manual for possible values

API Tags:
Access:  public

Information Tags:
Tutorial:  Adding attributes to field container

[ Top ]
removeField  [line 63]

  void removeField( string $fieldName  )

Remove field(under development)

Parameters:
string   $fieldName:  the name of the field

API Tags:
Access:  public


[ Top ]
render  [line 185]

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

Render form

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

API Tags:
Access:  public

Information Tags:
Tutorial:  RENDERING THE FORM

[ Top ]
renderForm  [line 109]

  void renderForm( [ $attributes = array()], [ $events = array()]  )

Alias of render()

Parameters:
   $attributes: 
   $events: 

API Tags:
Access:  public


[ Top ]
setInputStyle  [line 377]

  void setInputStyle( array $style, string $type  )

Change 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 365]

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

Change Labels 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 224]

  returns validate( )

Validate form fields defined with the addFieldValidator() method


API Tags:
Return:  fields to validate, an array with isValid(bool) and errors(array) as array keys
Access:  public

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

[ Top ]
validateEmail  [line 291]

  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 email is valid, false otherwise
Access:  public

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

[ Top ]
validateEqualTo  [line 312]

  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 matches another field value, false otherwise
Access:  public

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

[ Top ]
validateForm  [line 113]

  void validateForm( )

Alias of validate()


API Tags:
Access:  public


[ Top ]
validateNumber  [line 303]

  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, false otherwise
Access:  public

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

[ Top ]
validatePattern  [line 324]

  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 pattern is matched, false otherwise
Access:  public

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

[ Top ]
validateRequired  [line 283]

  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, false otherwise
Access:  public

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

[ Top ]
_addClassValidator  [line 862]

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

Add validator classes to field for js validation

Parameters:
string   $fieldName:  the name of the field
array|string   $options:  the options to pass("required","email")
string   $fieldType:  used by checkbox and radio groups only

API Tags:
Access:  protected


[ Top ]
_addCompositeField  [line 501]

  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:  add previously configured fields to a table layout("fieldName1","fieldName2")

API Tags:
Access:  protected


[ Top ]
_addDefaultValues  [line 520]

  void _addDefaultValues( string $array  )

Add empty default values when addField() is called

Parameters:
string   $array: 

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


[ Top ]
_addElementId  [line 984]

  void _addElementId( string $fieldName, string $arrKey  )

Add an id to all html elements

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

API Tags:
Access:  protected


[ Top ]
_addFieldParams  [line 752]

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

Add parameters to field

Parameters:
string   $fieldName:  the name of the field
array   $type:  ("events","attributes","validate","label","labelOptions","parentEl","value")
array|string   $options:  the options to pass,view manual for details

API Tags:
Access:  protected


[ Top ]
_addInputStyle  [line 887]

  void _addInputStyle( string $fieldName, string $fieldStyle  )

Add default style to field to align properly

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

API Tags:
Access:  protected


[ Top ]
_addLabelStyle  [line 905]

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

Add default style to label 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 920]

  void _addTableStyle( string $fieldName, string $tableStyle  )

Add default style to table to align properly

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

API Tags:
Access:  protected


[ Top ]
_addValidator  [line 839]

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

Add validator to input field

Parameters:
string   $fieldName:  the name of the field
array|string   $options:  the options to pass("required","email")

API Tags:
Access:  protected


[ Top ]
_buildAttributes  [line 958]

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

Build 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 482]

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

Build container for field

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

API Tags:
Access:  protected


[ Top ]
_buildElAttributes  [line 946]

  void _buildElAttributes( string $container  )

Replace $_elAttributes with template {attributes}

Parameters:
string   $container:  the container html element

API Tags:
Access:  protected


[ Top ]
_buildField  [line 555]

  void _buildField( string $fieldName  )

Build fields

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

API Tags:
Access:  protected


[ Top ]
_buildHtml  [line 1021]

  void _buildHtml( string $fieldName  )

Build container for field

Parameters:
string   $fieldName:  the name of the field

API Tags:
Access:  protected


[ Top ]
_buildLabel  [line 1112]

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

Build 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 999]

  void _buildList( string $fieldName  )

Build html select options

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

API Tags:
Access:  protected


[ Top ]
_buildTableData  [line 680]

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

Build 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 1205]

  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)
string   $function:  which function called this process
string   $errType:  the error type

API Tags:
Access:  protected


[ Top ]
_editFormValues  [line 1270]

  void _editFormValues( array $array  )

Manipulate form values from POST or GET

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

API Tags:
Access:  protected


[ Top ]
_getFormValues  [line 1258]

  void _getFormValues( )

Retrieve form values from POST or GET


API Tags:
Access:  protected


[ Top ]
_randomId  [line 1281]

  void _randomId( )

Increase number of random generated id for elements


API Tags:
Access:  protected


[ Top ]
_rebuildValues  [line 1057]

  void _rebuildValues( string $fieldName  )

Rebuild values for fields if POST or GET

Parameters:
string   $fieldName:  the name of the field

API Tags:
Access:  protected


[ Top ]
_switchLabelEl  [line 533]

  void _switchLabelEl( string $fieldName, string $labelText  )

Switch 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 Wed, 06 Mar 2013 23:45:44 +0100 by phpDocumentor 1.4.3