Class: PtcForms
Source Location: /workshop/PhpToolCase/current/PtcForms.php
Class PtcForms
Property Summary
array |
$_htmlTpls |
Html templates property for all elements |
array |
$_validate |
Array of fields to validate with the validator engine |
Method Summary
PtcForms |
__construct() |
Sets form method(POST/GET) and retrieves sent values |
void |
addElAttributes() |
Adds attributes to array of attributes for html elements |
void |
customTpls() |
Manipulates html templates for all elements |
returns |
validate() |
Validate form fields defined with the "validate" parameter |
void |
_addLabelStyle() |
Adds default style to the label container to align properly |
void |
_addTableStyle() |
Adds default style to the table to align properly |
void |
_checkErrors() |
Checks for errors while building and rendering the form |
void |
_randomId() |
Increases number of random generated id for elements |
void |
_rebuildValues() |
Rebuilds values for the fields if form has been sent |
void |
_switchLabelEl() |
Switches between span and label elements according to field type |
Properties
Build hidden values property
API Tags:
Default options for the class
API Tags:
Information Tags:
Html attributes for all elements
API Tags:
Information Tags:
Fields storage property
API Tags:
Auto generated hidden fields storage
API Tags:
Html templates property for all elements
API Tags:
Information Tags:
Default input styles options property
API Tags:
Information Tags:
Default label styles property
API Tags:
Information Tags:
Possible options in fields storage
API Tags:
Array of fields to validate with the validator engine
API Tags:
Information Tags:
Methods
PtcForms __construct(
[array
$options = null]
)
|
|
Sets form method(POST/GET) and retrieves sent values
Parameters:
API Tags:
Information Tags:
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:
Information Tags:
void addElement(
array
$params
)
|
|
Adds a field to the form object
Parameters:
array |
$params: |
parameters for the field |
API Tags:
Information Tags:
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:
void customTpl(
$templates
)
|
|
Alias of customTpls()
Parameters:
API Tags:
void customTpls(
array
$templates
)
|
|
Manipulates html templates for all elements
Parameters:
array |
$templates: |
array of html templates |
API Tags:
Information Tags:
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:
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:
Information Tags:
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:
Information Tags:
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:
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 |
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 |
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 |
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 |
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 |
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:
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:
void _addDefaultValues(
string
$array
)
|
|
Adds empty default values when addElement() is called
Parameters:
API Tags:
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:
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:
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:
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:
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:
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:
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:
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:
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:
void _buildElAttributes(
string
$container
)
|
|
Compiles _elAttributes with the template {attributes}
Parameters:
string |
$container: |
the html element |
API Tags:
void _buildField(
string
$fieldName
)
|
|
Builds the fields
Parameters:
string |
$fieldName: |
the name of the field |
API Tags:
void _buildHtml(
string
$fieldName
)
|
|
Builds container for the field
Parameters:
string |
$fieldName: |
the name of the field |
API Tags:
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:
void _buildList(
string
$fieldName
)
|
|
Builds html select options
Parameters:
string |
$fieldName: |
the name of the select field |
API Tags:
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:
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:
void _editFormValues(
array
$array
)
|
|
Manipulates form values from POST or GET
Parameters:
array |
$array: |
array of values(POST or GET) |
API Tags:
Retrieves form values from POST or GET
API Tags:
Increases number of random generated id for elements
API Tags:
void _rebuildValues(
string
$fieldName
)
|
|
Rebuilds values for the fields if form has been sent
Parameters:
string |
$fieldName: |
the name of the field |
API Tags:
void _removeField(
string
$fieldName
)
|
|
Removes a field from the object
Parameters:
string |
$fieldName: |
the name of the field to be removed |
API Tags:
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:
|
|