Jeff PHP framework  0.99
Modular, extensible, OOP, MVC, lightweight php framework designed to ease the programmers in the development of web applications.
form Class Reference

Class used to manage forms. More...

Public Member Functions

 __construct ($method, $name, $opts=null)
 Constructs a form instance.
 captcha ($opts=null)
 Captcha field (image and input field)
 ccaptcha ($opts=null)
 Captcha complete field (label, image and input field)
 ccheckbox ($name, $checked, $value, $label, $opts=null)
 Complete checkbox form element (label and input element)
 cform ()
 Form close tag.
 checkbox ($name, $checked, $value, $opts=null)
 Checkbox form element.
 checkCaptcha ()
 Captcha code check.
 checkRequired ()
 Checks if the required fields have been filled.
 cinput ($name, $type, $value, $label, $opts)
 Complete form input element (label and input field)
 cinput_date ($name, $value, $label, $opts)
 Complete form date input element (label and input field)
 cinput_datetime ($name, $value, $label, $opts)
 Complete form datetime input element (label and input field)
 cinput_file ($name, $value, $label, $opts=null)
 Complete form input file element.
 cmulticheckbox ($name, $checked, $values, $label, $opts=null)
 Complete multi checkbox form elements (label and elements)
 cradio ($name, $value, $data, $default, $label, $opts=null)
 Complete form radio button (label and input element)
 cselect ($name, $value, $data, $label, $opts=null)
 Complete form select element (label and select element)
 ctextarea ($name, $value, $label, $opts=null)
 Complete form textarea element (label and textarea)
 fieldset ($legend, $content, $opts=null)
 Fieldset element.
 free ()
 Deletes the session array used to save and load submitted data.
 freeInput ($cleft, $cright, $opts=null)
 Custom content formatted as a form element (label and field)
 hidden ($name, $value, $opts=null)
 Hidden field.
 input ($name, $type, $value, $opts=null)
 Form input element.
 input_file ($name, $value, $opts=null)
 Form input file element.
 label ($text)
 Label preparation.
 load ($noerror=false)
 Loads the submitted data previously saved to session.
 multiplecheckbox ($name, $checked, $values, $opts=null)
 Multi checkbox form elements.
 radio ($name, $value, $data, $default, $opts)
 Form radio button.
 retvar ($name, $dft=null)
 Retrieves the value of a variable loaded from session (and so previously submitted)
 save ()
 Saves submitted data to session.
 select ($name, $selected, $data, $opts)
 Select form element.
 setRequired ($required)
 Sets the required fields.
 sform ($action, $required, $opts=null)
 Form open tag.
 textarea ($name, $value, $opts)
 Textarea form element.
 uploadFile ($name, $valid_extension, $path, $link_error, $opts)
 Management of form file uploads.
 uploadImage ($name, $valid_extension, $path, $link_error, $opts)
 Uploads the submitted image to the given directory.

Private Member Functions

 checkExtension ($filename, $valid_extension)
 Checks if the file extension is allowed.
 generateFormToken ()
 CSRF token generation.
 prepareView ($name, $l, $d, $req, $tadd, $opts=null)
 Prepare the form element view.
 setFileName ($name, $path, $prefix)
 Sets the upload file name.
 upload ($tmp_file, $filename, $path)
 Upload a file to the given directory.
 verifyFormToken ()
 CSRF token verification.

Private Attributes

 $_method
 form method (post or get)
 $_name
 form name and id
 $_registry
 the registry singleton instance
 $_requestVars
 Array containing the submitted data.
 $_validation
 whether to add javascript validation or not
 $_view
 a view instance

Detailed Description

Class used to manage forms.

Author:
abidibo abidi.nosp@m.bo@g.nosp@m.mail..nosp@m.com
Version:
0.99
Date:
2011-2012

Definition at line 30 of file form.class.php.


Constructor & Destructor Documentation

form::__construct ( method,
name,
opts = null 
)

Constructs a form instance.

Parameters:
string$methodform method: post or get
string$nameform name and id
array$optsassociative array of options:
  • validation: whether to perform javascript validation or not
  • verifyToken: whether to verify the token used to detect CSRF attacks or not
Returns:
void

Definition at line 73 of file form.class.php.

+ Here is the call graph for this function:


Member Function Documentation

form::captcha ( opts = null)

Captcha field (image and input field)

Parameters:
array$optsassociative array of options:
  • class: css class of the div which contains the captcha
Returns:
void

Definition at line 275 of file form.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

form::ccaptcha ( opts = null)

Captcha complete field (label, image and input field)

Parameters:
array$optsassociative array of options:
  • text_add: text added after the field
  • see form
Returns:
void

Definition at line 257 of file form.class.php.

+ Here is the call graph for this function:

form::ccheckbox ( name,
checked,
value,
label,
opts = null 
)

Complete checkbox form element (label and input element)

Parameters:
string$namefield name
bool$checkedwhether to check the field or not
mixed$valuefield value
mixed$labelfield label
mixed$optsassociative array of options:
  • text_add: text added after the field
  • see form
Returns:
the complete checkbox element

Definition at line 795 of file form.class.php.

+ Here is the call graph for this function:

Form close tag.

Returns:
string the form close tag

Definition at line 242 of file form.class.php.

form::checkbox ( name,
checked,
value,
opts = null 
)

Checkbox form element.

Parameters:
string$namefield name
bool$checkedwhether to check the field or not
mixed$valuefield value
mixed$optsassociative array of options:
  • id: string. id attribute of the element
  • classField: string. css class of the element
  • required: bool. whether the field is required or not
  • js: string. js event handler
  • other: string. other element attributes
Returns:
the checkbox element

Definition at line 820 of file form.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Captcha code check.

Returns:
bool, check result

Definition at line 291 of file form.class.php.

+ Here is the call graph for this function:

form::checkExtension ( filename,
valid_extension 
) [private]

Checks if the file extension is allowed.

Parameters:
string$filenamefile name
array$valid_extensionlist of valid extensions
Returns:
bool, the check result

Definition at line 1242 of file form.class.php.

+ Here is the caller graph for this function:

Checks if the required fields have been filled.

Returns:
bool, the check result, true if all required fields were filled, false otherwise

Definition at line 197 of file form.class.php.

+ Here is the call graph for this function:

form::cinput ( name,
type,
value,
label,
opts 
)

Complete form input element (label and input field)

Parameters:
string$namefield name
string$typeinput type
mixed$valuefield value
mixed$labelfield label
mixed$optsassociative array of options:
  • text_add: text added after the field
  • see form
Returns:
the complete input element

Definition at line 475 of file form.class.php.

+ Here is the call graph for this function:

form::cinput_date ( name,
value,
label,
opts 
)

Complete form date input element (label and input field)

Parameters:
string$namefield name
string$valuefield value
mixed$labelfield label
mixed$optsassociative array of options:
  • text_add: text added after the field
  • see form except from options size, maxlength, pattern, hint which have default values
Returns:
the complete datetime element

Definition at line 496 of file form.class.php.

+ Here is the call graph for this function:

form::cinput_datetime ( name,
value,
label,
opts 
)

Complete form datetime input element (label and input field)

Parameters:
string$namefield name
string$valuefield value
mixed$labelfield label
mixed$optsassociative array of options:
  • text_add: text added after the field
  • see form except from options size, maxlength, pattern, hint which have default values
Returns:
the datetime element

Definition at line 540 of file form.class.php.

+ Here is the call graph for this function:

form::cinput_file ( name,
value,
label,
opts = null 
)

Complete form input file element.

Parameters:
string$namefield name
string$valuefield value
mixed$labelfield label
mixed$optsassociative array of options:
  • extensions: array. List of valid file extensions
  • text_add: text added after the field
  • see form
Returns:
the complete input file element

Definition at line 910 of file form.class.php.

+ Here is the call graph for this function:

form::cmulticheckbox ( name,
checked,
values,
label,
opts = null 
)

Complete multi checkbox form elements (label and elements)

Parameters:
string$namefield name
array$checkedarray containing the checked items
array$valuesarray of items in the form array(array('label'=>'item_label', 'value'=>'item_value'))
mixed$labelform label
mixed$optsassociative array of options:
  • label_class: label css class
  • text_add: text added after the field
  • see form
Returns:
the complete multicheck element

Definition at line 847 of file form.class.php.

+ Here is the call graph for this function:

form::cradio ( name,
value,
data,
default,
label,
opts = null 
)

Complete form radio button (label and input element)

Parameters:
string$namefield name
mixed$valuefield value
array$dataradio choices in the array form array('value'=>'label')
mixed$defaultdefault choice selected
mixed$labelfield label
mixed$optsassociative array of options:
  • text_add: text added after the field
  • required: bool. whether the field is required or not
  • see form
Returns:
the complete radio button

Definition at line 657 of file form.class.php.

+ Here is the call graph for this function:

form::cselect ( name,
value,
data,
label,
opts = null 
)

Complete form select element (label and select element)

Parameters:
string$namefield name
mixed$valuefield value
array$dataselect options in the array form array('value'=>'label')
mixed$labelfield label
mixed$optsassociative array of options:
  • text_add: text added after the field
  • see form
Returns:
the complete select element

Definition at line 716 of file form.class.php.

+ Here is the call graph for this function:

form::ctextarea ( name,
value,
label,
opts = null 
)

Complete form textarea element (label and textarea)

Parameters:
string$namefield name
string$valuefield value
mixed$labelfield label
mixed$optsassociative array of options:
  • text_add: text added after the field
  • see form
Returns:
the complete textarea element

Definition at line 585 of file form.class.php.

+ Here is the call graph for this function:

form::fieldset ( legend,
content,
opts = null 
)

Fieldset element.

Parameters:
string$legendthe legend content
string$contentthe fieldset content
mixed$optsassociative array of options:
  • id: fieldset id
Returns:
the fieldset element

Definition at line 311 of file form.class.php.

+ Here is the call graph for this function:

Deletes the session array used to save and load submitted data.

Returns:
void

Definition at line 174 of file form.class.php.

form::freeInput ( cleft,
cright,
opts = null 
)

Custom content formatted as a form element (label and field)

Parameters:
string$cleftleft content (as a label)
string$crightright content (as an input)
mixed$optsassociative array of options:
  • idLeft: string. id attribute of the left content
  • idRight: string. id attribute of the right content
Returns:
void

Definition at line 400 of file form.class.php.

+ Here is the call graph for this function:

form::generateFormToken ( ) [private]

CSRF token generation.

Returns:
the generated token

Definition at line 99 of file form.class.php.

+ Here is the caller graph for this function:

form::hidden ( name,
value,
opts = null 
)

Hidden field.

Parameters:
string$namefield name
mixed$valuefield value
array$optsassociative array of options:
  • id: field id
Returns:
void

Definition at line 351 of file form.class.php.

+ Here is the caller graph for this function:

form::input ( name,
type,
value,
opts = null 
)

Form input element.

Parameters:
string$namethe field name
string$typethe input type (text, password, checkbox, ...)
mixed$valuethe input value
mixed$optsassociative array of options:
  • id: string. id attribute of the input element
  • class: string. css class of the input element
  • pattern: string. pattern attribute of the input element
  • hint: string. hint message shown when the specified pattern checks fails
  • placeholder: string. placeholder attribute of the input element
  • size: string. size attribute of the input element
  • maxlength: string. maxlength attribute of the input element
  • readonly: bool. whether the input element is readonly or not
  • required: bool. whether the field is required or not
  • formnovalidate: bool. whether the input element is not to be validated or not
  • js: string. js event handler
  • other: string. other element attributes
Returns:
the input element

Definition at line 433 of file form.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

form::input_file ( name,
value,
opts = null 
)

Form input file element.

Parameters:
string$namefield name
string$valuefield value
mixed$optsassociative array of options:
  • rel_path: string. Relative path of the directory of upload
  • preview: whether to show a lightbox style file previwe or not (to use with images only)
  • see form
Returns:
the input file element

Definition at line 934 of file form.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

form::label ( text)

Label preparation.

Parameters:
mixed$textlabel text. Possible values are:
  • string: the label text
  • array: the first or 'label' element is the label text, the second or 'description' element is the description text
Returns:
void

Definition at line 329 of file form.class.php.

+ Here is the caller graph for this function:

form::load ( noerror = false)

Loads the submitted data previously saved to session.

Parameters:
bool$noerrorwhether to loads data even if no error occurs
Returns:
void

Definition at line 127 of file form.class.php.

form::multiplecheckbox ( name,
checked,
values,
opts = null 
)

Multi checkbox form elements.

Parameters:
string$namefield name
array$checkedarray containing the checked items
array$valuesarray of items in the form array(array('label'=>'item_label', 'value'=>'item_value'))
mixed$optsassociative array of options:
  • id: string. id attribute of every single element
  • classField: string. css class of every single element
  • js: string. js event handler of every single element
  • other: string. other element attributes of every single element
Returns:
the multicheck element

Definition at line 872 of file form.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

form::prepareView ( name,
l,
d,
req,
tadd,
opts = null 
) [private]

Prepare the form element view.

Parameters:
string$namefield name
mixed$lfield label
mixed$dfield label description
bool$reqwhether the field is required or not
string$taddtext added after the input element
mixed$optsassociative array of options:
  • label_class: string. css class for the label element
  • label_form: string. form attribute of the label element
  • more: string. Additional content after the input element and text added
Returns:
void

Definition at line 373 of file form.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

form::radio ( name,
value,
data,
default,
opts 
)

Form radio button.

Parameters:
string$namefield name
mixed$valuefield value
array$dataradio choices in the array form array('value'=>'label')
mixed$defaultdefault choice selected
mixed$optsassociative array of options:
  • aspect: string. whether the choices should be vertically or horizontally listed
  • id: string. id attribute of the element
  • js: string. js event handler
  • other: string. other element attributes
Returns:
the radio button

Definition at line 682 of file form.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

form::retvar ( name,
dft = null 
)

Retrieves the value of a variable loaded from session (and so previously submitted)

Parameters:
string$namethe field name
mixed$dftdeafult value if variable was not loaded
Returns:
void

Definition at line 163 of file form.class.php.

Saves submitted data to session.

Returns:
void

Definition at line 148 of file form.class.php.

form::select ( name,
selected,
data,
opts 
)

Select form element.

Parameters:
string$namefield name
mixed$valuefield value
array$dataselect options in the array form array('value'=>'label')
mixed$optsassociative array of options:
  • id: string. id attribute of the element
  • classField: string. css class of the select element
  • size: string. size attribute of the select element
  • multiple: bool. whether to allow multiple selection or not
  • required: bool. whether the field is required or not
  • js: string. js event handler
  • other: string. other element attributes
  • firstVoice: string. custom first option label
  • firstValue: string. custom first option value
  • noFirst: bool. Whether to show or not an empty first option
  • maxChars: int. If set the option labels are cut at the given number of characters
  • cutWords: bool default false. Whether to allow cut of words when truncating labels or not
Returns:
the select element

Definition at line 748 of file form.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

form::setFileName ( name,
path,
prefix 
) [private]

Sets the upload file name.

If another file with the same name exists in the upload directory adds .1, .2, etc.. at the end of the name

Parameters:
string$namefile name
string$pathabsolute path of the upload directory
string$prefixfile name prefix
Returns:
the file name

Definition at line 1221 of file form.class.php.

+ Here is the caller graph for this function:

form::setRequired ( required)

Sets the required fields.

Parameters:
string$requiredcomma separated list of required fields
Returns:
void

Definition at line 186 of file form.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

form::sform ( action,
required,
opts = null 
)

Form open tag.

Parameters:
string$actionform action attribute
string$requiredcomma separated list of required fields
mixed$optsAssociative array:
  • upload: bool. Whether the form allows file upload or not
  • generateToken: bool. Whether the generate a CSRF token
Returns:
the form open tag

Definition at line 223 of file form.class.php.

+ Here is the call graph for this function:

form::textarea ( name,
value,
opts 
)

Textarea form element.

Parameters:
string$namefield name
string$valuefield value
mixed$optsassociative array of options:
  • editor: whether to charge dojo editor or not
  • id: string. id attribute of the textarea element
  • class: string. css class of the textarea element
  • pattern: string. pattern attribute of the textarea element
  • hint: string. hint message shown when the specified pattern checks fails
  • placeholder: string. placeholder attribute of the textarea element
  • cols: int. cols attribute of the textarea element
  • rows: int. rows attribute of the textarea element
  • readonly: bool. whether the textarea element is readonly or not
  • required: bool. whether the field is required or not
  • js: string. js event handler
  • other: string. other element attributes
Returns:
the texarea element

Definition at line 615 of file form.class.php.

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

form::upload ( tmp_file,
filename,
path 
) [private]

Upload a file to the given directory.

Parameters:
string$tmp_filename of the temporary file
string$filenamename of the file saved to filesystem
string$pathpath of the saving directory
Returns:
bool, result of file uploading

Definition at line 1262 of file form.class.php.

+ Here is the caller graph for this function:

form::uploadFile ( name,
valid_extension,
path,
link_error,
opts 
)

Management of form file uploads.

Method for managing files via the upload form. If a new file is uploaded the old file is deleted.

The old file can also be deleted without uploading a new one. If no file is uploaded and the deletion checkbox in the input file element is unchecked then all stands as is.

Parameters:
string$namefield name
array$valid_extensionlist of valid extensions
string$pathabsolute path to the upload directory
string$link_errorredirection url in case of error
mixed$optsassociative array of options:
  • error_query: string. Query to execute in case of file upload error
  • check_content: string. Whether to check file mime type or not
  • contents: array. List of allowed mime types, if not given the default one is taken
  • prefix: string. Filename prefix
  • max_file_size: int. Maximum size allowed for the file
Returns:
the name of the uploaded file or an empty string or the old file name

Definition at line 979 of file form.class.php.

+ Here is the call graph for this function:

form::uploadImage ( name,
valid_extension,
path,
link_error,
opts 
)

Uploads the submitted image to the given directory.

Method for managing images via the upload form. If a new file is uploaded the old file is deleted.

The old file can also be deleted without uploading a new one. If no file is uploaded and the deletion checkbox in the input file element is unchecked then all stands as is.

Parameters:
string$namefield name
array$valid_extensionlist of valid extensions
string$pathabsolute path to the upload directory
string$link_errorredirectino url in case of error
mixed$optsassociative array of options:
  • error_query: string. Query to execute in case of file upload error
  • check_content: string. Whether to check file mime type or not
  • contents: array. List of allowed mime types, if not given the default one is taken
  • prefix: string. Filename prefix
  • prefix_thumb: string default 'thumb_'. Thumbnail prefix
  • make_thumb: bool default false. Whether to create a thumbnail or not
  • resize: bool default false. Whether to resize the image or not
  • scale: bool default false. Whether to scale the image or not
  • resize_enlarge: bool default false. Whether to allow image enlargement during resizing or not
  • resize_width: int default null. With used to resize the image (if only width or height are given the proportions are maintained)
  • resize_height: int default null. Height used to resize the image
  • thumb_width: int default null. With of the thumbnail (if only width or height are given the proportions are maintained)
  • thumb_height: int default null. Height of the thumbnail
  • max_file_size: int. Maximum size allowed for the file
Returns:
void

Definition at line 1090 of file form.class.php.

+ Here is the call graph for this function:

form::verifyFormToken ( ) [private]

CSRF token verification.

Returns:
bool, the verification result

Definition at line 110 of file form.class.php.

+ Here is the caller graph for this function:


Field Documentation

form::$_method [private]

form method (post or get)

Definition at line 45 of file form.class.php.

form::$_name [private]

form name and id

Definition at line 50 of file form.class.php.

form::$_registry [private]

the registry singleton instance

Definition at line 35 of file form.class.php.

Array containing the submitted data.

Definition at line 60 of file form.class.php.

form::$_validation [private]

whether to add javascript validation or not

Definition at line 55 of file form.class.php.

form::$_view [private]

a view instance

Definition at line 40 of file form.class.php.


The documentation for this class was generated from the following file: