pclib
3.0.0
Lightweight PHP framework
|
Create and manage forms. More...
Public Member Functions | |
validate () | |
Do form validation - return true if form pass validation rules. More... | |
loadSession () | |
Load form values from session. More... | |
saveSession () | |
Save form values to session. More... | |
isEditable ($id, $testAttr=true) | |
Is element $id editable? | |
create ($tableName, $templatePath='') | |
Use default template for displaying database table content. | |
getValue ($id) | |
Return form value. | |
print_Element ($id, $sub, $value) | |
This function is called for each template tag when it is printed. More... | |
print_Errors () | |
Print form error messages. More... | |
print_Class ($id, $sub, $value) | |
Print all form elements at once. More... | |
print_Label ($id) | |
Print label for form field. More... | |
print_Input ($id, $sub, $value) | |
Print HTML input field. More... | |
print_Text ($id, $sub, $value) | |
Print HTML TEXTAREA field. More... | |
print_Button ($id, $sub, $value) | |
Print form button. More... | |
print_Checkbox_Radio_Group ($id, $sub, $value) | |
Print group of radiobuttons or checkboxes. More... | |
print_Checkbox ($id, $sub, $value, $i=null) | |
Print INPUT TYPE=CHECKBOX field. More... | |
print_Radio ($id, $sub, $value, $i=null) | |
Print INPUT TYPE=RADIO field. More... | |
print_ListInput ($id, $sub, $value) | |
Print HTML5 input with datalist. More... | |
print_Select ($id, $sub, $value) | |
Print HTML SELECT field. More... | |
preparedValues ($skipEmpty=false) | |
Prepare form values for storing into database. More... | |
upload ($tableName, $id, $old=[]) | |
Upload form files. More... | |
getFile ($id) | |
Return content of uploaded file. More... | |
insert ($tab) | |
Insert form values into db-table $tab and save uploaded files into specified directory. More... | |
update ($tab, $cond) | |
Update form record in database table $tab, using where-condition $cond. More... | |
delete ($tab, $cond) | |
Delete form record and remove attached files (if any). More... | |
content () | |
Return array of label => value(s) pairs for all elements of the form. More... | |
mailTo ($to, $subj, $intro='', $hdr='') | |
Send form by mail. More... | |
dbSync ($tab) | |
Set maxlength and size of the form fields, according underlying database table. More... | |
Public Member Functions inherited from Tpl | |
__construct ($path='', $sessName='') | |
Load and parse template file. More... | |
init () | |
Initialization - must be called after load() | |
load ($path) | |
Load template file. More... | |
loadString ($s) | |
Load string $s as template. More... | |
out ($block=null) | |
Display template populated with content. More... | |
html ($block=null) | |
Return html output of the template populated with content. More... | |
enable () | |
Enable (show) or disable (hide) tag or block $name. More... | |
disable () | |
Disable (hide) tag or block $name. More... | |
setAttr ($id, $value, $value2=null) | |
Set attribute globally for template elements. More... | |
getBlock ($block) | |
Return values of block $block. More... | |
deleteSession () | |
Remove object from session. | |
print_Number ($id, $sub, $value) | |
Print numeric $value. More... | |
print_String ($id, $sub, $s) | |
Print string $value. More... | |
print_Bind ($id, $sub, $value) | |
Bind $value to LABEL coming from datasource and print LABEL. More... | |
print_Link ($id, $sub, $value) | |
Create html link. More... | |
print_Env ($id, $sub, $value) | |
Print value from url (from _GET array). More... | |
print_Action ($id, $sub, $value) | |
Call controller's method and include result into template. More... | |
print_Block ($block) | |
Print template block. More... | |
addTag ($line) | |
Add new element. More... | |
addType ($name, $fn) | |
Add new type of element handled by callback function $fn. More... | |
setFields ($fields) | |
Show only this $fields in template (using tag {grid.fields} or {form.fields}). More... | |
htmlTag ($name, $attr=[], $content=null) | |
Return html tag $name with attributes. More... | |
Public Member Functions inherited from BaseObject | |
loadDefaults ($className=null) | |
Load default parameters of class $className into object instance. | |
setProperties (array $defaults) | |
Set public properties of object from the array. More... | |
toArray () | |
Convert object to array. More... | |
Data Fields | |
$submitted | |
When form has been submitted, it contains name of pressed button. | |
$invalid = [] | |
Array of error messages filled by validate() function. More... | |
$submitDisabledInputs = true | |
Should submit disabled input fields? | |
$uploadBlackList = array('*.php','*.php?','*.phtml','*.exe','.htaccess') | |
Files matching patterns cannot be uploaded by Form class. | |
$useButtonTag = true | |
Generate buttons with html button tag or as input type=button. | |
Data Fields inherited from Tpl | |
$name | |
Name of the template. | |
$elements = array() | |
Array of elements loaded from <?elements ? > section. | |
$values = array() | |
Array of template values. | |
$db | |
var Db | |
$router | |
var Router | |
$escapeHtmlFunction | |
Function for escaping html in template values. | |
Data Fields inherited from BaseObject | |
$serviceLocator | |
var function() Return service object when requested with service(). | |
Protected Member Functions | |
_out ($block=null) | |
Display form. More... | |
getHttpData () | |
Return sanitized _POST (_GET) data. More... | |
getTag ($id, $ignoreHtmlAttr=false) | |
Prepare form tag with common attributes. More... | |
checkboxToArray ($value) | |
Convert checkbox $value (int|string) to array. | |
trPrintElement ($elem) | |
Helper for print_class() | |
divPrintElement ($elem) | |
Helper for print_class() | |
fileName ($id) | |
Create file name based on element attributes. | |
toSqlDate ($dtstr, $fmtstr='') | |
HUMAN DATE => DATABASE DATE. | |
toNumber ($value) | |
Bypass non-numerical characters. | |
toBitField (array $bitArray) | |
Convert array of bits to integer. | |
escape ($s) | |
escape value for using in form input | |
head () | |
return <form> header | |
foot () | |
return </form> footer html | |
Protected Member Functions inherited from Tpl | |
getAttr ($id, $attr) | |
Return attribute of element $id. More... | |
getVariable ($id) | |
Get template variable tvar... | |
getRowNo () | |
Return row number of the current block. | |
createFromTable ($tableName, $templatePath) | |
Use default template for displaying database table content. | |
compute ($id) | |
Return computed value of element $id. | |
getPopup ($id, $attr, $url) | |
Generate javascript code for popup window. More... | |
getUrl ($elem) | |
Return url for the element (button, link) with completed parameters. | |
formatDate ($dtstr, $fmt='') | |
DATABASE DATE => HUMAN DATE (in date() format) More... | |
formatStr ($s, $fmt) | |
Format string $s according format $fmt. | |
getItems ($id) | |
Load lookup table for elements such as bind, select, check or radio. More... | |
Protected Member Functions inherited from BaseObject | |
service ($service, $default=null) | |
Try acquire $service and load it into property $this->$service. More... | |
Protected Attributes | |
$validator | |
var FormValidator Form validator. | |
$className = 'form' | |
Name of the 'class' element. | |
Protected Attributes inherited from Tpl | |
$sessName | |
Name of the session variable where template values are stored. More... | |
$app | |
var App Link to application object. | |
$config = null | |
Link to array of configuration parameters. | |
$document | |
Document array - It contains parsed template. | |
$parser | |
var TplParser | |
$fields = [] | |
List of id's to be printed in {grid.fields} tag. | |
$types = [] | |
Additional element type handlers. | |
Additional Inherited Members | |
Static Public Member Functions inherited from BaseObject | |
static | defaults () |
Set or retireve default parameters of the object. More... | |
Create and manage forms.
Features:
See Template tags implemented by class Form for description of implemented tags.
In addition, you can use common template elements (see Template tags implemented by class Tpl)
|
protected |
Display form.
string | $block | If set, only block $block will be shown. |
Reimplemented from Tpl.
content | ( | ) |
Return array of label => value(s) pairs for all elements of the form.
Helper for showing form content to the end user. Used in mailTo().
dbSync | ( | $tab | ) |
Set maxlength and size of the form fields, according underlying database table.
$tab | Table name |
delete | ( | $tab, | |
$cond | |||
) |
Delete form record and remove attached files (if any).
string | $tab | database table name |
string | $cond | where-condition of the query |
getFile | ( | $id | ) |
Return content of uploaded file.
string | $id | Input id |
|
protected |
Return sanitized _POST (_GET) data.
|
protected |
Prepare form tag with common attributes.
insert | ( | $tab | ) |
Insert form values into db-table $tab and save uploaded files into specified directory.
Columns of the table must have same names like keys in $values array. Convert numbers, dates and checkboxes to database format automatically.
string | $tab | database table name |
loadSession | ( | ) |
Load form values from session.
Called when $sessname in constructor is set. Do not call directly. Useful, if you need keep form values after page-reload.
Reimplemented from Tpl.
mailTo | ( | $to, | |
$subj, | |||
$intro = '' , |
|||
$hdr = '' |
|||
) |
Send form by mail.
string | $to | - destination mail address |
string | $subj | - mail subject |
string | $intro | - text of the mail before list of form values |
string | $hdr | - headers |
preparedValues | ( | $skipEmpty = false | ) |
Prepare form values for storing into database.
Convert date, number, remove unwanted fields etc.
bool | $skipEmpty | Remove empty fields? |
print_Button | ( | $id, | |
$sub, | |||
$value | |||
) |
Print form button.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_Checkbox | ( | $id, | |
$sub, | |||
$value, | |||
$i = null |
|||
) |
Print INPUT TYPE=CHECKBOX field.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_Checkbox_Radio_Group | ( | $id, | |
$sub, | |||
$value | |||
) |
Print group of radiobuttons or checkboxes.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_Class | ( | $id, | |
$sub, | |||
$value | |||
) |
Print all form elements at once.
Uses simple table layout for presentation. Implement {form.fields} placeholder.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
Reimplemented from Tpl.
print_Element | ( | $id, | |
$sub, | |||
$value | |||
) |
This function is called for each template tag when it is printed.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
Reimplemented from Tpl.
print_Errors | ( | ) |
print_Input | ( | $id, | |
$sub, | |||
$value | |||
) |
Print HTML input field.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_Label | ( | $id | ) |
Print label for form field.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_ListInput | ( | $id, | |
$sub, | |||
$value | |||
) |
Print HTML5 input with datalist.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_Radio | ( | $id, | |
$sub, | |||
$value, | |||
$i = null |
|||
) |
Print INPUT TYPE=RADIO field.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_Select | ( | $id, | |
$sub, | |||
$value | |||
) |
Print HTML SELECT field.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
print_Text | ( | $id, | |
$sub, | |||
$value | |||
) |
Print HTML TEXTAREA field.
string | $id | name of template tag {ID} |
string | $sub | modificator (second part) of template tag name {ID.sub} |
mixed | $value | value of element going from Tpl->values array |
saveSession | ( | ) |
update | ( | $tab, | |
$cond | |||
) |
Update form record in database table $tab, using where-condition $cond.
string | $tab | database table name |
string | $cond | where-condition of query |
upload | ( | $tableName, | |
$id, | |||
$old = [] |
|||
) |
Upload form files.
array | $old | List of previous versions of files - will be deleted |
validate | ( | ) |
Do form validation - return true if form pass validation rules.
Scan $elements and check validation rules, which are set in elements section of form template. If user does not fill form properly validate() return false and template tags {errors} and {TAGNAME.err} are set with error messages. You can use predefined validation rules with attributes required,email,date,number,file (see Template tags implemented by class Form) or even define your own rule (see PClib callback functions)
$invalid = [] |
Array of error messages filled by validate() function.
Error messages can be shown using {errors} or {fieldname.err} tag in template.