easyFormProc v1.1.0
This is a handy class that will create and handle all the process of the elements in a form. The processes include form posting, validation and retrieving the posted values. I have added few common validation functions. Custom functions can also be added.
Files
class.easyformproc.inc.php - The class file you need to include to your script.
functions.validation.inc.php - The file that contains all the validation function. New custom functions can be added to this file.
Functions of the Class
Samples
Release updates
1.0.1 - Bugfix : Output HTML string of the combobox didn't contain space between attributes. Space added between attributes in the <select> element
1.0.2 - Bugfix : Striping slashes of posted values were done regardless of the Strip slashes of magic_quotes_gpc setting in php.ini. Strip slashes in only done when this setting is set to ON
1.0.5 - Update : getBrowserSafePostedElementValues() function added to the class. It can be used to get safer posted values to output it to the browser to avoid cross site scripting
1.0.6 - BugFix : Posted values are now captured when an identifier is used for submit button except the default value
1.0.8 - Update : Option to add query string when the form is posted
1.1.0 - File fields now support null validation
Email your suggestions and bug reports to me at nazly dot net
void setTextElement(string indentifier[, string value[, int maxlength[, int size[, string style[, string validate[, string errormsg[, array params]]]]]]])
Description : Creates a text element.
Returns : nothing
Parameters
indentifier : Element identifier
value : Default value
maxlength : Maximum Characters allowed
size : Width of the textbox
style : Style class
validate : Validation function
errormsg : Error message if validation returns false
params : Addtional parameters to be passed to the validation function
void setTextAreaElement(string indentifier[, string value[, int columns[, int numlines[, string style[, string validate[, string errormsg[, array params]]]]]]])
Description : Creates a textarea element.
Returns : nothing
Parameters
indentifier : Element identifier
value : Default value
columns : Width of the textarea
numlines : Number of lines in the textarea
style : Style class
validate : Validation function
errormsg : Error message if validation returns false
params : Addtional parameters to be passed to the validation function
void setPasswordElement(string indentifier[, string value[, int maxlength[, int size[, string style[, bool showDefault[, mixed validate[, string errormsg]]]]]]])
Description : Creates a password element.
Returns : nothing
Parameters
indentifier : Element identifier
value : Default value
maxlength : Maximum Characters allowed
size : Width of the textbox
style : Style class
showDefault : Set TRUE to display the default value on the password box.
validate : Set TRUE to check not emtpty or to compare with another element set its identifier
errormsg : Error message if validation returns false
void setHiddenElement(string indentifier[, string value])
Description : Creates a hidden element.
Returns : nothing
Parameters
indentifier : Element identifier
value : Default value
void setSelectElement(string indentifier[, array values[, mixed selected[, string style[, int height[, bool multiple[, string validate[, string errormsg[, array params]]]]]]]])
Description : Creates a select element.
Returns : nothing
Parameters
indentifier : Element identifier
values : Default list of values (Associative array)
selected : Selected value (Values should be passed as an array if multiple selection is allowed)
style : Style class
height : Heigth of the select box
multiple : Set TRUE if multiple selection is allowed
validate : Validation function
errormsg : Error message if validation returns false
params : Addtional parameters to be passed to the validation function
void setRadioElement(string indentifier[, array values[, string checked[, string style[, string validate[, string errormsg[, array params]]]]]])
Description : Creates a group of radio elements.
Returns : nothing
Parameters
indentifier : Element identifier
values : Default list of values (Associative array)
checked : Checked value
style : Style class
validate : Validation function
errormsg : Error message if validation returns false
params : Addtional parameters to be passed to the validation function
void setCheckElement(string indentifier[, array values[, array checked[, string style[, string validate[, string errormsg[, array params]]]]]])
Description : Creates a group of checkbox elements.
Returns : nothing
Parameters
indentifier : Element identifier
values : Default list of values (Associative array)
checked : Checked list of values
style : Style class
validate : Validation function
errormsg : Error message if validation returns false
params : Addtional parameters to be passed to the validation function
void setFileElement(string indentifier[, string style[, bool validate[, string errormsg[, int maxsize[, array mimetypes]]]]])
Description : Creates a file element.
Returns : nothing
Parameters
indentifier : Element identifier
style : Style class
validate : Validates the file
errormsg : Error message if validation fails
maxsize : Maximum allowed capacity for the file (in Kilobytes)
mimetypes : Allowed MIME types
array processForm(string submitbuttonlabel[, string submitbuttonstyle[, string submitbuttonidentifier[, string overwritedefaction]]])
Description : Processes the form after all elements have been set
Returns : HTML of Form and Submit Button
Parameters
submitbuttonlabel : Label of the submit button
submitbuttonstyle : Style class for the submit button
submitbuttonidentifier : Submit button identifier
overwritedefaction : Overwrite Form Action (action to be set to the same page but can be with a querystring)
array getDisElementHTML()
Description : Get HTML of all elements
Returns : HTML of all elements
bool isPosted()
Description : Identifies whether the form is posted or not
Returns : TRUE if form is posted and FALSE otherwise
array getPostedElementValues()
Description : Get all posted values of the elements in the form
Returns : Posted values
array getBrowserSafePostedElementValues()
Description : Get all posted values of the elements in the form that are safer for browser output.
Returns : Posted values
string getErrorMsg([string errorheader[, string style]])
Description : Get Error Message.
Returns : Error messages