FORM SETUP
Change Default Form ACTION
Change Default Form METHOD
Set Form ID
Set Form NAME
Other Form Attributes (enctype,accept,onsubmit,onreset,accept-charset)
Check for Allowed Hosts
This feature allows you to check the referer and compare it to the values you have set up in the array.
If the domain is not in this array, the form will not be processed.
(only use "localhost" for your testing.)
$form->checkAllowedHosts( array( "localhost" ) );
Use Fieldset and Set Legend for Form
If you want to use a fieldset and set a legend for the form, you can do it as follows:
$form->layout->setFieldset(true);
$form->layout->setFieldsetLegend("My Form Class Test");
checkdnsrr (validate email domain)
If you want to use this option, use the method below to activate it.
This will only be aplicable to input fields, that have the "check" parameter defined as "email" (in which case normal email pattern matching is carried out anyway)
$form->setCheckDNSRR(true);
If you activate this option, the script will look up the host and validate it.
Allowed MIME types
If you want to limit the types of files that can be uploaded through the form, use the method below.
You will need to create an array of allowed MIME types (as in the example below).. and then call the method to activate the option.
$allowed_uploads = array(
'image/pjpeg'=>'jpg',
'image/jpeg'=>'jpg',
'image/gif'=>'gif',
'image/x-png'=>'png'
);
$form->setAllowedMIME( $allowed_uploads );
When you activate this option... any file upload will be checked... and not processed, if MIME type is not in the array.
Defining "disabled", "readonly", "tabindex", "accesskey", etc...
Most of the elements allow you to pass a string (called attrib in the function) to them.
This string will be added inside the the element tag without any validation.
So, if you decide to use this, you must yourself take care that it is xhtml compliant and that it works correctly.
This value is always the last value in the function to be passed, if you need to use this, you will need to set all the other optional stuff too.
You can pass several things in this at once if you wish.
for example:
"disabled='disabled' readonly='readonly' maxlength='10' or what ever.
Some of the events commonly attached to form elements are, for example:
disabled, readonly, maxlength, tabindex, accesskey, accept...
See xhtml documentation for full list and usage.
Defining your own javascript for elements
Most of the elements allow you to pass a string (called attrib in the function) to them.
This string will be added inside the the element tag without any validation.
So, if you decide to use this, you must yourself take care that it is xhtml compliant and that it works correctly.
This value is always the last value in the function to be passed, if you need to use this, you will need to set all the other optional stuff too.
You can pass several things in this at once if you wish.
for example:
"onfocus='javascript:function1();' onblur='javascript:function2();'"
Some of the events commonly attached to form elements are, for example:
onfocus, onblur, onselect, onchange, onclick, ondblclick, onmousedown, onmouseup, onmouseover, onmousemove, onmouseout, onkeypress, onkeydown, onkeyup
Defining ELEMENTS
INPUT
Following values can be passed to this create method:
NAME, CHECK, REQUIRED, Size, LABEL, VALUE, ATTRIBUTES
Only Name is required for basic functionality
// INPUT VARIABLES -> NAME, CHECK, REQUIRED, Size, LABEL, VALUE, ATTRIBUTES
$name = $form->createInput("name","string",true,10,"Your Name", "");
$email = $form->createInput("email","email");
$phone = $form->createInput("phone","phone",false);
Name -- always needed (used as id and name, as well as label if none defined)
Check -- Type of checking to be performed on this input ("string,"email","phone","captcha")
Required -- If the field is required to be filled
Size -- size of input field
Label -- Define a label to be displayed (else label = Name)
Value -- Prefill the input with a value
---------------
Attributes = Here you can pass in any setup you want (not validated - XHTML compliance not checked)
for example:
"onchange='javascript:function()'" or anynything else applicable to the element
This is always the last value, and is not needed unless you want to add extra functionality.
SELECT
Following values can be passed to this create method:
NAME, LABEL, SELECTED, OPTIONS, ATTRIBUTES
Only Name And Options are required for basic functionality
// SELECT VARIABLES -> NAME, LABEL, SELECTED, OPTIONS, ATTRIBUTES
$usetype = $form->createSelect( "usetype","","",array("Commercial","Private") );
You can also use arrays of arrays to define option groups with labels:
$options = array (
"Group 1" => array( "option 1", "option 2", "option 3" ),
"Group 2" => array( "option 4", "option 5","option 6" ),
"Group 3" => array( "option 7", "option 8", "option 9" )
);
$options = $form->createSelect( "options","Option Groups","",$options );
Name -- always needed (used as id and name, as well as label if none defined)
Label -- Define a label to be displayed (else label = Name)
Selected -- Preselected value
Options -- Array() of options to include in the select
---------------
Attributes = Here you can pass in any setup you want (not validated - XHTML compliance not checked)
for example:
"onchange='javascript:function()'" or anynything else applicable to the element
This is always the last value, and is not needed unless you want to add extra functionality.
SELECT (BOOLEAN)
Following values can be passed to this create method:
NAME, LABEL, SELECTED, ATTRIBUTES
Only Name is required for basic functionality
// BOOLEAN VARIABLES -> NAME, LABEL, SELECTED, ATTRIBUTES
$subscribe = $form->createBoolean("subscribe","Receive Newsletter", 1);
Name -- always needed (used as id and name, as well as label if none defined)
Label -- Define a label to be displayed (else label = Name)
Selected -- Preselected value
---------------
Attributes = Here you can pass in any setup you want (not validated - XHTML compliance not checked)
for example:
"onchange='javascript:function()'" or anynything else applicable to the element
This is always the last value, and is not needed unless you want to add extra functionality.
SELECT (NUM)
Following values can be passed to this create method:
NAME, FROM, TO, INCR, SELECT, LABEL, ATTRIBUTES
Select and Label are Optional
// SELECT NUM -> NAME, FROM, TO, INCR, SELECT, LABEL, ATTRIBUTES
$licenses = $form->createSelectNum("licenses",1,10,1,2,"Licenses Required");
Name -- always needed (used as id and name, as well as label if none defined)
From -- Start from number
To -- Up to number
Incr -- in increments of
Select -- Preselected value
Label -- Define a label to be displayed (else label = Name)
---------------
Attributes = Here you can pass in any setup you want (not validated - XHTML compliance not checked)
for example:
"onchange='javascript:function()'" or anynything else applicable to the element
This is always the last value, and is not needed unless you want to add extra functionality.
SELECT (MULTIPLE)
Following values can be passed to this create method:
NAME, LABEL, SIZE, OPTIONS, ATTRIBUTES
// SELECT MULTIPLE -> NAME, LABEL, SIZE, OPTIONS, REQUIRED, ATTRIBUTES
$lang = $form->createSelectMultiple("languages","",3,array("PHP","Ruby","Java","C++"),false );
Name -- always needed (used as id and name, as well as label if none defined)
Label -- Define a label to be displayed (else label = Name)
Size -- size of input field (shown rows height)
Options -- Array() of options to include in the select
Required -- define if the element is required (true or false)
---------------
Attributes = Here you can pass in any setup you want (not validated - XHTML compliance not checked)
for example:
"onchange='javascript:function()'" or anynything else applicable to the element
This is always the last value, and is not needed unless you want to add extra functionality.
TEXTAREA
Following values can be passed to this create method:
NAME, COLS, ROWS, REQUIRED, CONTENT, LABEL, ATTRIBUTES
Only Name is required for basic functionality
// TEXTAREA -> NAME, COLS, ROWS, REQUIRED, CONTENT, LABEL, ATTRIBUTES
$info = $form->createTextarea("info",30,3,false,$info_content,"Additional Information");
Name -- always needed (used as id and name, as well as label if none defined)
Cols -- textarea columns size
Rows -- textarea rows size
Required -- If the field is required to be filled
Content -- Prefilled value
Label -- Define a label to be displayed (else label = Name)
---------------
Attributes = Here you can pass in any setup you want (not validated - XHTML compliance not checked)
for example:
"onchange='javascript:function()'" or anynything else applicable to the element
This is always the last value, and is not needed unless you want to add extra functionality.
RADIO
Following values can be passed to this create method:
NAME, REQUIRED, LABEL, SELECTED, ARRAY, ATTRIBUTES
Only Name and Array are required for basic functionality
// RADIO BUTTONS -> NAME, REQUIRED, LABEL, SELECTED, ARRAY, ATTRIBUTES
$package = $form->createRadio("package",false,"","",array("Package 1","Package 2","Package 3") );
Name -- always needed (used as id and name, as well as label if none defined)
Required -- If the field is required to be filled
Label -- Define a label to be displayed (else label = Name)
Selected -- Preselected value
Array -- Array() of options to include in the select
---------------
Attributes = Here you can pass in any setup you want (not validated - XHTML compliance not checked)
for example:
"onchange='javascript:function()'" or anynything else applicable to the element
This is always the last value, and is not needed unless you want to add extra functionality.
CHECKBOX
Following values can be passed to this create method:
NAME, SELECTED, LABEL, OPTIONS, ATTRIBUTES
Only Name and Options are required for basic functionality
This Function returns an ARRAY!!
// CHECK BOXES (Returns Array) -> NAME, SELECTED, LABEL, OPTIONS, ATTRIBUTES
$bundle = $form->createCheckboxes("bundle","","Add",array("Bundle 1","Bundle 2","Bundle 3") );
Name -- always needed (used as id and name, as well as label if none defined)
Selected -- Preselected value
Label -- Define a label to be displayed (else label = Name)
Options -- Array() of options to include in the select
---------------
Attributes = Here you can pass in any setup you want (not validated - XHTML compliance not checked)
for example:
"onchange='javascript:function()'" or anynything else applicable to the element
This is always the last value, and is not needed unless you want to add extra functionality.
HIDDEN
Following values can be passed to this create method:
NAME, VALUE
// HIDDEN FIELDS -> NAME, VALUE
$maxsize = $form->createHidden("MAX_FILE_SIZE","100000");
Name -- always needed (used as id and name)
Value -- value for the hidden field
If you use the above example, and set "MAX_FILE_SIZE", then that value will also be used in post processing file size validation in PHP
FILE UPLOAD
You can either upload a single file... or multiple files.
Remember that you need to set the enctype for the form to use uploads:
$form->setEnctype("multipart/form-data");
You can also set allowed MIME types for files that are uploaded. See Form Setup section.
Upload File uploadFile()
Following values can be passed to this create method:
NAME, LABEL, TARGET, CHMOD, SIZE, ATTRIBUTES
This method returns the path to the moved file in target directory
// FILE UPLOAD -> NAME, LABEL, TARGET, CHMOD, SIZE, ATTRIBUTES
$filename = $form->uploadFile("upload","Choose File","uploads/","644",30);
Upload Multiple Files uploadMultiple()
Following values can be passed to this create method:
NAME, LABEL, TARGET, CHMOD, SIZE, MAX, ADDLINK, ATTRIBUTES
This method returns an array of paths to the moved files in target directory
// FILE UPLOAD MULTIPLE-> NAME, LABEL, TARGET, CHMOD, SIZE, MAX, ADDLINK, ATTRIBUTES
//$files_array = $form->uploadMultiple("upload","Choose","uploads/","644",5,30,"Add");
Name -- always needed (used as id and name, as well as label if none defined)
Label -- Define a label to be displayed (else label = Name)
Target -- Define the target directory for upload (must end with "/")
Chmod -- Define chmod for moved file, if you wish
Size -- size of inputbox
Max -- Maximum files allowed for uploading multiple mode
Addlink -- label of link to add more fileuploads
---------------
Attributes = Here you can pass in any setup you want (not validated - XHTML compliance not checked)
for example:
"onchange='javascript:function()'" or anynything else applicable to the element
This is always the last value, and is not needed unless you want to add extra functionality.
CAPTCHA
Following values can be passed to this create method:
NAME, SessionName, LABEL, Size, ImgURL, ATTRIBUTES
You should be able to use this with any normal captcha script...
The current method is setup for my own captcha script.
http://downloads.jv2.net/captcha/
You will see in the examples that the "ImgURL" is defined to start with "/". This is because I have mine in the root. You can of course change the location...
// CAPTCHA -> NAME, SessionName, LABEL, Size, ImgURL, ATTRIBUTES
//$form->createCaptcha("captcha","random","Verification",6,"/captcha/captcha.php?id=".time() );
Name -- always needed (used as id and name, as well as label if none defined)
SessionName -- Name of session variable to store the captcha code
Label -- Define a label to be displayed (else label = Name)
Size -- size of input box
ImgURL -- url of file which generates image and session variable
---------------
Attributes = Here you can pass in any setup you want (not validated - XHTML compliance not checked)
for example:
"onchange='javascript:function()'" or anynything else applicable to the element
This is always the last value, and is not needed unless you want to add extra functionality.
SUBMIT
There are two methods of creating submit buttons:
For a single button you can use:
$form->createSubmit("Submit");
Or for multiple buttons on the same row, you can use:
$form->createSubmitMultiple( array("Update","Delete") );
Name -- name for submit button
array -- array of names for submit buttons
RESET
Following values can be passed to this create method:
NAME
$form->createReset("Reset");
Name -- name for reset button
Formatting
Using either Table or P mode
To change the layout of the form... try one of the following:
$form->layout->setUseTable(true);
$form->layout->setUseTable(4);
$form->layout->setUseTable(false);
Accepted Values are (true, false, 2, 4)
If you are using 4... then you will need to change the order you define the form elements, as that affects the order they are inserted in the table.
Adding breaks in P mode
If you are using the P mode [setUseTable(false)], then you may want to add breaks between the label and form element (unless you already do that in css by setting display:block for the legend)
$form->layout->setAdd_BR(true);
Adding an Empty Row or Paragraph
If you need to add an empty row for formatting (useful for organising things in the 4 column table layout), use the following method:
$form->addEmpty();
Radio options displayed inline (flow)
Default for displaying radio options is new line for each.
If you wish to have them displayed next to each other on one line, call the following method, before setting up the radio options.
$form->layout->setRadioInlineFlow(true);
Checkbox options displayed inline (flow)
Default for displaying checkbox options is new line for each.
If you wish to have them displayed next to each other on one line, call the following method, before setting up the checkbox options.
$form->layout->setCheckInlineFlow(true);
Style / CSS
Set ID and/or Class for Form
Set ID and/or Class for Table
If you wish to use an ID or Class for the Table, you can set them with the following methods:
$form->layout->setTableID("tableid");
$form->layout->setTableClass("tableclass");
Setting STYLE tags to the table and cells.
If you wish to add style tags to the table and/or cells(columns), you have the following methods available to you:
$form->layout->setStyleTable("style='border:0px;'");
$form->layout->setStyleColumn1("style='text-align:right;vertical-align:top;'");
$form->layout->setStyleColumn2("style='text-align:left;vertical-align:top;'");
$form->layout->setStyleColumn3("style='text-align:right;vertical-align:top;'");
$form->layout->setStyleColumn4("style='text-align:left;vertical-align:top;'");
The values shown are the defaults, you do not need to use these methods unless you want to change them.