Class: PtcForms
Source Location: /workshop/PhpToolCase/current/PtcForms.php
Class PtcForms
Method Summary
PtcForms |
__construct() |
Sets form method(POST/GET) and retrieves already sent values |
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 |
fieldParentEl() |
Add attributes to div container for input field |
void |
_checkErrors() |
Checks for errors while building and rendering the form |
void |
_randomId() |
Increase number of random generated id for elements |
void |
_switchLabelEl() |
Switch between span and label elements according to field type |
Properties
build hidden values parameter
API Tags:
default options
API Tags:
html attributes for all elements
API Tags:
auto generated hidden fields storage
API Tags:
default Input styles options
API Tags:
possible options in fields storage
API Tags:
array of fields to validate
API Tags:
Methods
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:
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:
Information Tags:
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:
Information Tags:
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:
Information Tags:
void addFieldEvent(
$fieldName,
$options
)
|
|
Alias of addFieldEvents()
Parameters:
API Tags:
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:
Information Tags:
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:
Information Tags:
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:
Information Tags:
void addFieldValue(
$fieldName,
$options
)
|
|
Alias of addFieldValues()
Parameters:
API Tags:
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:
Information Tags:
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:
Information Tags:
void addSpacer(
[string
$spacerVal = null]
)
|
|
Add spacer div
Parameters:
string |
$spacerVal: |
the height for the spacer in px |
API Tags:
Information Tags:
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:
Information Tags:
void customTpl(
$templates
)
|
|
Alias of customTpls()
Parameters:
API Tags:
void customTpls(
array
$templates
)
|
|
Manipulate html templates
Parameters:
array |
$templates: |
array of html templates |
API Tags:
Information Tags:
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:
Information Tags:
void removeField(
string
$fieldName
)
|
|
Remove field(under development)
Parameters:
string |
$fieldName: |
the name of the field |
API Tags:
void render(
[array
$attributes = array()], [array
$events = array()]
)
|
|
Render form
Parameters:
array |
$attributes: |
add form attributes |
array |
$events: |
add form events |
API Tags:
Information Tags:
void renderForm(
[
$attributes = array()], [
$events = array()]
)
|
|
Alias of render()
Parameters:
API Tags:
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:
Information Tags:
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:
Information Tags:
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:
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:
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:
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:
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:
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:
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:
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:
void _addDefaultValues(
string
$array
)
|
|
Add empty default values when addField() is called
Parameters:
API Tags:
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:
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:
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:
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:
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:
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:
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:
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:
void _buildElAttributes(
string
$container
)
|
|
Replace $_elAttributes with template {attributes}
Parameters:
string |
$container: |
the container html element |
API Tags:
void _buildField(
string
$fieldName
)
|
|
Build fields
Parameters:
string |
$fieldName: |
the name of the input field |
API Tags:
void _buildHtml(
string
$fieldName
)
|
|
Build container for field
Parameters:
string |
$fieldName: |
the name of the field |
API Tags:
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:
void _buildList(
string
$fieldName
)
|
|
Build 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
)
|
|
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:
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:
void _editFormValues(
array
$array
)
|
|
Manipulate form values from POST or GET
Parameters:
array |
$array: |
array of values(POST or GET) |
API Tags:
Retrieve form values from POST or GET
API Tags:
Increase number of random generated id for elements
API Tags:
void _rebuildValues(
string
$fieldName
)
|
|
Rebuild values for fields if POST or GET
Parameters:
string |
$fieldName: |
the name of the field |
API Tags:
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:
|
|