PHP Forms Class with HTML Generator and JavaScript Validation: HTML forms generation and validation.

Recommend this page to a friend!
  Info   Example   Demos   Screenshots   View files (138)   Download .zip   Reputation   Support forum (254)   Blog (8)    
Last Updated Ratings Unique User Downloads Download Rankings
2019-09-20 (10 months ago) 81%Total: 88,201 This week: 11All time: 1 This week: 24
Version License PHP version Categories
formsgeneration 1.0.29BSD License4HTML, Validation, AJAX
Description Author

Class that generates HTML forms supporting:

- Multiple inputs may be interconnected in such way that client side events that occur on one input can trigger actions on the context of other inputs. Developers may use input interconnection support without writing Javascript code.
- Can be extended with new types of input controls plug-in classes.
- Custom input plug-in classes can be used to support for handling client site events on the server side without submitting the form or redrawing the whole form page
- Some control plug-in classes are made available:
* AJAX based form submission (without reloading the whole page)
* Auto-complete text inputs
* Select a location on a map using Google Maps API
* Calendar date input
* CAPTCHA test to prevent automated access by robots
* Linked select input to switch select options when the value of another input changes. An unlimited number of selected can be linked in cascade. Additional plug-in subclasses are provided to retrive option groups from a MySQL database or many other SQL databases using the Metabase PEAR::MDB2 PHP database abstraction layer APIs
* Manage animations that apply visual effects to the page form elements, like: fade-in, fade-out, show, hide, update content, etc..
- XHTML compliant output.
- Load submitted form field values even with register_globals option Off and strip slashes when magic_quotes_gpc option is On.
- Keyboard navigation support:
* Attachment of labels with activation keys to each form field.
* Tab navigation order index.
- Built-in server side (PHP based) and client side (Javascript 1.0 or better) field validation for:
* E-mail address
* Credit card numbers (Visa, Mastercard, American Express, Discover, Diners Club, Carte Blanche, enRoute, JCB, any of these or even determined by a select field).
* Regular expressions.
* Field not empty.
* Field equal to another (useful for password confirmation fields).
* Field different from another (useful for reminder fields that must not be equal to the actual password).
* As set (for check boxes, radio buttons and select multiple fields).
* As integer number (with range limitation).
* As floating point number (with range limitation).
* Programmer defined client and server validation functions.
- Highlight invalid fields rendering them distinct CSS styles
- Security attack prevention by optionally discarding invalid values passed in fields that could not be edited by users but may be spoofed by attackers.
- Option to define a value that, when used in a field, it is accepted without performing any of the validations defined for the field.
- Ability to stop the user from submiting a form more than once inadvertdly.
- Sub form validation (validate only smaller set of field depending on the submit button that was used).
- Composition and generation of the form HTML output with fields displayed as fully accessible or in read-only mode.
- Generation of Javascript functions (useful to set to the page ONLOAD event):
* Set the input focus to a field.
* Select the text of a field.
* Set the input focus and select the text of a field.
* Enable and disable input fields
- Automatic capitalization of the text of a field:
* Upper case.
* Lower case.
* Word initials
- Replacement of text field expressions to perform adjustments like trimming whitespace or auto-complete values based on rules defined by regular expressions
- Compose forms with templates using plain HTML files with embedded PHP code or using the Smarty template engine with a supplied pre-filter plugin
- Etc.

Recommendations

AJAX functions to update page elements
I need to be able to use a set of generic AJAX function calls

PHP API Key Generator
A random API key generator to server as access restriction to AP

mlm dynamic binary tree code in PHP and MySQL
mlm dynamic binary tree

PHP Navigation bar with CodeIgniter
Problem with the URL

Dynamic class for CRUD with MySQL database
Form processing to MySQL database storage

What is the best PHP grid crud postgresql class?
Class to enable browsing a PostgreSQL database

Spell check for PHP
I need to check textareas

Price checking availability using barcode scanner by mobile apps
Example source code in barcode scanner

Reading changed check boxes
Need to read changes in check boxes

dropdown dependency
i need the code and explation of dropdown dependency

What is the best PHP youtube video downloader class?
Download videos from YouTube

What is the best PHP responsive forms generator class?
Responsive forms with all kind of elements (date, text, etc.)

Form validation + form generation + mysqli query+security filter
Make a CMS from simple class

Remote PHP app to alter database
I need to manipulate a MySQL database on my website with browser

What is the best PHP AJAX file upload class?
I want to upload files using AJAX

What is the best PHP tab based forms class?
Design a data entry form with tabs

Large file upload handler
Looking for class that will handle large file uploads

Create file structure based on text string
Need to dynamically create a file system structure on the fly

What is the best PHP data validation classes class?
Customer details form validation like phone and email

What is the best PHP multiple tabs form class?
I want to use form with multiple tabs and validations

Could you suggest a good form validator?
I need a RAD form validator

Vectorize a map in defined points
I need to vectorize points in a geographical map image

Form Listview with dependent field
I need to create a form using dependent listboxes

Filtration mechanism
Filtration mechanism in shopping portal

How to create related dropdown list box?
cannot link 2nd dropdown list box with first one

Job application form
Single form to be feed by applicant for the job

how to make
large form handle design pattern

I need php class which converts word format to html
I need php class which converts word format to html

Implement image CAPTCHA validation
a class to implement image captcha via an Ajax request

What is the best PHP crud class?
Basic insert, update, list, delete with pagination and images

Picture of Manuel Lemos
  Performance   Level  
Name: Manuel Lemos is available for providing paid consulting. Contact Manuel Lemos .
Classes: 41 packages by
Country: Portugal Portugal
Age: 51
All time rank: 1
Week rank: 4 1 in Portugal Portugal

Details

PHP Form Example

Include the forms class directly or use vendor/autoload.php if you install it with composer.

require("forms.php");

Create a form object.

$form=new form_class;

Define the name of the form to be used for example in Javascript validation code generated by the class.

$form->NAME="subscription_form";

Use the GET method if you want to see the submitted values in the form processing URL, or POST otherwise.

$form->METHOD="POST";

Make the form be displayed and also processed by this script.

$form->ACTION="";

Specify a debug output function you really want to output any programming errors.

$form->debug="trigger_error";

Define a warning message to display by Javascript code when the user attempts to submit the this form again from the same page.

$form->ResubmitConfirmMessage=
    "Are you sure you want to submit this form again?";

Output previously set password values.

$form->OutputPasswordValues=1;

Output multiple select options values separated by line breaks

$form->OptionsSeparator="<br />\n";

Output all validation errors at once.

$form->ShowAllErrors=1;

CSS class to apply to all invalid inputs. Set to a non-empty string to specify the invalid input CSS class

$form->InvalidCLASS='invalid';

Style to apply to all invalid inputs when you just want to override a few style attributes, instead of replacing the CSS class. Set to a non-empty string to specify the invalid input style attributes

$form->InvalidSTYLE='background-color: #ffcccc; border-color: #000080';

Text to prepend and append to the validation error messages.

$form->ErrorMessagePrefix="- ";
$form->ErrorMessageSuffix="";

Define the form field properties even if they may not be displayed.

$form->AddInput(array(
    "TYPE"=>"text",
    "NAME"=>"email",
    "ID"=>"email",
    "MAXLENGTH"=>100,
    "Capitalization"=>"lowercase",
    "ValidateAsEmail"=>1,
    "ValidationErrorMessage"=>"It was not specified a valid e-mail address.",
    "LABEL"=>"<u>E</u>-mail address",
    "ACCESSKEY"=>"E"
));

$form->AddInput(array(
    "TYPE"=>"submit",
    "ID"=>"button_subscribe",
    "VALUE"=>"Submit subscription",
    "ACCESSKEY"=>"u"
));

PHP Form Validation

Load form input values eventually from the submitted form.

$form->LoadInputValues($form->WasSubmitted("doit"));

Empty the array that will list the values with invalid field after validation.

$verify=array();

Check if the was submitted as opposed to being displayed for the first time.

if($form->WasSubmitted())
{

Therefore we need to validate the submitted form values.

    if(($error_message=$form->Validate($verify))=="")
    {

It's valid, set the $doit flag variable to 1 to tell the form is ready to processed.

        $doit=1;

    }
    else
    {

It's invalid, set the $doit flag to 0 and encode the returned error message to escape any HTML special characters.

        $doit=0;
        $error_message=nl2br(HtmlSpecialChars($error_message));
    }
}
else
{

The form is being displayed for the first time, so it is not ready to be processed and there is no error message to display.

    $error_message="";
    $doit=0;
}

if($doit)
{

The form is ready to be processed, just output it again as read only to display the submitted values. A real form processing script usually may do something else like storing the form values in a database.

  $form->ReadOnly=1;
}

If the form was not submitted or was not valid, make the page ONLOAD event give the focus to the first form field or the first invalid field.

if(!$doit)
{
    if(strlen($error_message))
    {

If there is at least one field with invalid values, get the name of the first field in error to make it get the input focus when the page is loaded.

        Reset($verify);
        $focus=Key($verify);
    }
    else
    {

Make the email field get the input focus when the page is loaded if there was no previous validation error.

        $focus='email';
    }

Connect the form to the field to get the input focus when the page loads.

    $form->ConnectFormToInput($focus, 'ONLOAD', 'Focus', array());
}

PHP HTML Form Example Output

$onload = HtmlSpecialChars($form->PageLoad());

?><!DOCTYPE>
<html>
<head>
<title>Test for Manuel Lemos' PHP form class</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8">
<style type="text/css"><!--
    .invalid { border-color: #ff0000; background-color: #ffcccc; }
// --></style>
</head>
<body onload="<?php echo $onload; ?>" bgcolor="#cccccc">
<h1>Test for Manuel Lemos' PHP form class</h1>
<hr />

Compose the form output by including a HTML form template with PHP code interleaaved with calls to insert form input field parts in the layout HTML.

$form->StartLayoutCapture();
$title="Form class test";
$body_template="form_body.html.php";
require("templates/form_frame.html.php");
$form->EndLayoutCapture();

Output the form using the function named Output.

$form->DisplayOutput();

?></body>
</html>
  All examples   AJAX form submission   Auto Complete   Form CRUD   General Example   Google Maps integration   Linked select inputs   Maps   Multiple Tabs   AJAX Form Submission  

Open in a separate window

Open in a separate window

Open in a separate window

Open in a separate window

Open in a separate window

Open in a separate window

Open in a separate window

Open in a separate window

Open in a separate window

Open in a separate window

  Files  
File Role Description
smarty (2 directories)
templates (24 files)
test (1 file, 2 directories)
test_form.php Example Forms class test page script
forms.html Doc. Forms class documentation in HTML format
animation.js Data Javascript class to use with the page element animation plug-in
blog_post_data_source.php Class Blog post data source class for the crude example script
blog_post_model.php Class Example blog post model class for the scaffolding example script
blog_post_view.php Class Example Blog post presentation definition class for the scaffolding example
country_codes.php Aux. Country codes definitions for the maps example
forms.php Class Forms class file
form_ajax_submit.php Class Custom plug-in class to submit forms with AJAX to not need to reload the page
form_animation.php Class Page element animation plug-in
form_auto_complete.php Class Custom plug-in class to auto-complete text entered in text inputs
form_captcha.php Class Custom input plug-in class for implementing CAPTCHA tests to prevent robots access allowing only humans
form_crud.php Class Custom input to handle scaffolding CRUD events by accessing data source objects.
form_custom_validation.php Class Example plug-in class to demonstrate how to perform new arbitrary validation types
form_date.php Class Custom input plug-in class for editing calendar dates
form_html_editor.php Class HTML editor plug-in input class
form_layout_paged.php Class Custom container input class to layout inputs in tabbed pages
form_layout_vertical.php Class Custom container plug-in class to render a group of inputs automatically without separate HTML or templates
form_linked_select.php Class Custom linked select input class
form_list_select.php Class Custom list select input class
form_map_location.php Class Custom input plug-in class for implementing a world map location selection input using Google Maps API
form_mdb2_auto_complete.php Class Custom auto complete input class using database queries with PEAR::MDB2 API
form_mdb2_linked_select.php Class Custom linked select input class that retrieves options from a database with the PEAR::MDB2 API adapted by Lukas Smith
form_metabase_auto_complete.php Class Custom plug-in class to auto-complete text entered in text inputs that retrieves completion texts dynamically from a database using the Metabase API
form_metabase_linked_select.php Class Custom linked select input plug-in class that retrieves options from a database with the Metabase API
form_mysqli_auto_complete.php Class Custom auto complete input class using MySQL database queries using MySQLi
form_mysqli_linked_select.php Class Custom linked select input class that retrieves options from a MySQL database using MySQLi
form_mysql_auto_complete.php Class Custom plug-in class to auto-complete text entered in text inputs that retrieves completion texts dynamically from a MySQL database
form_mysql_linked_select.php Class Custom linked select input plug-in class that retrieves options from a MySQL database
form_recaptcha.php Class reCAPTCHA custom input class
form_scaffolding.php Class Custom container input to manage scaffolding forms
form_secure_submit.php Class Secure form submit input plug-in class to prevent CSRF attacks
form_upload_progress.php Class Custom plug-in class to monitor the progress of upload of a form with files and show a progress bar
html_editor.js Data HTML editor Javascript class
indicator.gif Icon AJAX load indicator animation icon
locations.schema Data Locations database schema definition in format for the Metabase linked select inputs example
locations.sql Data Locations MySQL database schema dump for the linked select inputs example
markerclusterer.js Data MarkerClusterer Javascript class by Xiaoxi Wu
md5.js Data Henri Torgemane's Javascript md5 encoding function
noise.gif Data Example of noise GIF image to obfuscate the CAPTCHA input images
noise.png Data Example of noise PNG image to obfuscate the CAPTCHA input images
progress.gif Icon Upload progress bar stripe background image
pulldown.gif Icon Pulldown menu button icon image
README.md Data Description
rfc1867.php-4.3.11.patch Data Patch to enable upload progress monitoring in PHP 4.3.11
rfc1867.php-4.4.4.patch Data Patch to enable upload progress monitoring in PHP 4.4.4
rfc1867.php-4.4.9.patch Data Patch to enable upload progress monitoring in PHP 4.4.9 (use patch -p0 to apply)
setup_locations_database.php Aux. Script to install the locations database schema definition in format for the Metabase linked select inputs example
test_age_date_input.php Example Example to demonstrate how to use the custom date input with the ask age option
test_ajax_form.php Example Example to show how to define and process a form with AJAX submit plug-in
test_animation.php Example Example to demonstrate how to use the animation plug-in
test_animation_page.html Output Test HTML page generated by the class using test_animation.php script
test_auto_complete.html Output Test HTML page generated by the class using test_auto_complete.php script.
test_auto_complete.php Example Example to show how to use the auto-complete text custom input plug-in
test_auto_layout_form.php Example Example to show how to render a inputs with the automatic vertical layout plug-in
test_captcha_input.php Example Example to demonstrate how to use the custom CAPTCHA input plug-in
test_captcha_input_page.html Output Test HTML page generated by the class using test_captcha_input.php script.
test_crud_input.php Class Example to demonstrate how to use the scaffolding and crud inputs together
test_custom_validation.php Example Example to demonstrate how to use the custom validation plug-in
test_date_input.php Example Example to demonstrate how to use the custom date input plug-in
test_date_input_page.html Output Test HTML page generated by the class using test_date_input.php script.
test_dependent_validation.php Example Example to demonstrate how validate inputs depending on the state of a checkbox
test_encoded_password.php Example Example of password encoding before form submission
test_form_page.html Output Test HTML page generated by the class using test_form.html script.
test_form_results_page.html Output Test HTML results page generated by the class using test_form.html script.
test_html_editor.php Example Example to demonstrate how to use the HTML editor custom input
test_javascript_string_escaping.php Test Test script to verify the generation of escaped Javascript strings
test_linked_select.php Example Example to demonstrate how to link multiple select inputs
test_linked_select_page.html Output Test HTML page generated by the class using test_linked_select_input.php script.
test_list_select.php Example Example to demonstrate the list select input
test_map_location_input.php Example Example to demonstrate how to use the Google Maps map location custom input plug-in
test_mdb2_auto_complete.php Example Example to demonstrate how to auto-complete a text input with texts from a database using PEAR::MDB2 API
test_mdb2_linked_select.php Example Example to demonstrate how to link multiple select inputs retrieving options from a database with the PEAR::MDB2 API adapted by Lukas Smith
test_metabase_auto_complete.php Example Example to show how to use the auto-complete text custom input plug-in retrieving auto-complete texts from a database using the Metabase API
test_metabase_linked_select.php Example Example to demonstrate how to link multiple select inputs retrieving options from a database with the Metabase API
test_mysqli_auto_complete.php Example Example to demonstrate how to auto-complete a text input with texts from a MySQL database using MySQli
test_mysqli_linked_select.php Example Example to demonstrate how to link multiple select inputs retrieving options from a MySQL database using MySQLi
test_mysql_auto_complete.php Example Example to show how to use the auto-complete text custom input plug-in retrieving auto-complete texts from a MySQL database
test_mysql_linked_select.php Example Example to demonstrate how to link multiple select inputs retrieving options from a MySQL database
test_paged_layout_form.php Example Forms class example to render a inputs in tabbed pages with the paged layout plug-in
test_recaptcha_input.php Example Example to demonstrate how to use the reCAPTCHA custom input
test_scaffolding_input.php Example Example to demonstrate how to use the scaffolding input
test_secure_submit.php Example Example to demonstrate how use the secure submit custom input to prevent CSRF attacks
test_smarty3_form.php Example Forms class test page using Smarty 3 plug-in filter
test_smarty_form.php Example Forms class test page using Smarty 2 plug-in filter
test_upload.php Example File uploading example.
test_upload_progress.php Example Example to show how to use the form upload progress custom input plug-in

  Files  /  smarty  
File Role Description
2 (2 directories)
3 (2 directories)

  Files  /  smarty  /  2  
File Role Description
plugins (5 files)
templates_c (1 file)

  Files  /  smarty  /  2  /  plugins  
File Role Description
   insert.formadddatapart.php Aux. Smarty plug-in script to insert form data parts
   insert.formaddinputhiddenpart.php Aux. Smarty plug-in script to insert form input as hidden parts
   insert.formaddinputpart.php Aux. Smarty plug-in script to insert form input parts
   insert.formaddlabelpart.php Aux. Smarty plug-in script to insert form input label parts
   prefilter.form.php Aux. Smarty 2 engine pre-filter plugin for form template processing

  Files  /  smarty  /  2  /  templates_c  
File Role Description
   .htaccess Data Apache configuration file to forbid access to all files in this directory. This file is meant mostly to force the creation Smarty compiled templates directory templates_c.

  Files  /  smarty  /  3  
File Role Description
plugins (5 files)
templates_c (1 file)

  Files  /  smarty  /  3  /  plugins  
File Role Description
   insert.formadddatapart.php Aux. Smarty 3 plug-in script to insert form data parts
   insert.formaddinputhiddenpart.php Aux. Smarty 3 plug-in script to insert form input as hidden parts
   insert.formaddinputpart.php Aux. Smarty 3 plug-in script to insert form input parts
   insert.formaddlabelpart.php Aux. Smarty 3 plug-in script to insert form input label parts
   prefilter.form.php Aux. Smarty 3 engine pre-filter plugin for form template processing

  Files  /  smarty  /  3  /  templates_c  
File Role Description
   .htaccess Data Apache configuration file to forbid access to all files in this directory. This file is meant mostly to force the creation Smarty compiled templates directory templates_c.

  Files  /  templates  
File Role Description
   footer.tpl Data Example page footer Smarty template
   form.tpl Data Smarty HTML template for composing example form (copy to your Smarty templates directory)
   formerror.tpl Data Smarty template for displaying validation errors in the example form
   form_age_body.html.php Aux. Date custom input with the ask age option form body template
   form_ajax_body.html.php Aux. HTML template with embedded PHP to define the form body for the AJAX submit example
   form_animation.html.php Aux. Animation plug-in form template
   form_auto_complete_body.html.php Aux. HTML template with embedded PHP to define the form body for auto-complete text custom input plug-in
   form_auto_layout_body.html.php Aux. Template script to render the inputs of the automatic layout custom input plug-in
   form_body.html.php Aux. HTML template with embedded PHP to define the form body
   form_captcha_body.html.php Aux. CAPTCHA custom input form body template
   form_custom_validation.html.php Aux. Custom validation form body template
   form_date_body.html.php Aux. Date custom input form body template
   form_dependent_validation.html.php Aux. Dependent validation form body template
   form_frame.html.php Aux. HTML template with embedded PHP to define the form frame
   form_linked_select_body.html.php Aux. Linked selects form body template
   form_list_select_body.html.php Aux. List select input example form body template
   form_locations_aut...plete_body.html.php Aux. Auto-complete location input example form body template
   form_map_location_body.html.php Aux. Google Maps map location custom input form body template
   form_paged_layout_body.html.php Aux. Template script to render the inputs of the paged layout custom input plug-in
   form_password_body.html.php Aux. Encoded password form body template
   form_upload_body.html.php Aux. Upload file form body template
   header.tpl Data Example page header Smarty template
   message.html.php Data HTML template with embedded PHP to display a message feedback window
   mypage.tpl Data Example page wide Smarty template that integrates the form template output

  Files  /  test  
File Role Description
expect (13 files)
generated (1 file)
   test.php Test Unit test suite script

  Files  /  test  /  expect  
File Role Description
   all_client_errors_...date_input.php.html Data Expected output of the test_age_date_input.php script
   all_client_errors_...validation.php.html Data Expected output of the test_custom_validation.php script
   all_client_errors_...date_input.php.html Data Expected output of the test_date_input.php script
   all_client_errors_test_form.php.html Data Expected output of the test_form.php script showing all client validation errors
   all_server_errors_test_form.php.html Data Expected output of the test_form.php script after processing server validation showing all errors
   server_test_form.php.html Data Expected output of the test_form.php script after processing server validation errors
   set_age_date_test_date_input.php.html Data Expected output of the setagedate test
   set_date_test_date_input.php.html Data Expected output of the setdate text
   test_age_date_input.php.html Data Expected output of the test_age_date_input.php script
   test_custom_validation.php.html Data Expected output of the test_custom_validation.php script
   test_date_input.php.html Data Expected output of the test_date_input.php script
   test_form.php.html Data Expected output of the test_form.php script
   test_javascript_string_escaping.php.txt Data Expected ouput of the test to verify the escaping of Javascript strings.

  Files  /  test  /  generated  
File Role Description
   .cvsignore Data Dummy file to force the generated directory creation

formsgeneration-2019-09-20.zip 540KB
formsgeneration-2019-09-20.tar.gz 460KB
Install with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Metabase .zip .tar.gz Used by the custom linked select plug-in class that retrieves groups of options from many SQL databases Conditional
 Version Control Reuses Unique User Downloads Download Rankings  
 88%14
Total:88,201
This week:11
All time:1
This week:24
User Ratings User Comments (20)
 All time
Utility:87%
Consistency:83%
Documentation:74%
Examples:79%
Tests:76%
Videos:65%
Overall:81%
Rank:12
 
good
3 years ago (muabshir)
100%
Perfect
4 years ago (Umberto)
90%
cool
5 years ago (Yves Marie HAMAYON)
100%
Nice!!
5 years ago (Pedro Casado)
75%
Very useful class, very intelligent design.
6 years ago (Juan Carlos Neufeld)
82%
It does what it has to do.
9 years ago (Boulet Adrien)
90%
Olá Sr: Manuel Lemos, tenho pego muitos exemplos em seu site,...
9 years ago (Carlos Henrique Ponci)
50%
nice work, thank a lot!
9 years ago (bartb)
97%
goog
10 years ago (Naga Subrahmanyam)
80%
very good and easy to use and save time
10 years ago (Ashraf Mubarak)
95%
nice classes.
10 years ago (Surya Pradinata)
90%
Õëàì
10 years ago (Ewg)
2%
This is a good class!.
11 years ago (Iaster C Aki)
80%
Forms generation and validation package mostly suited for lea...
11 years ago (Allay)
67%
if the java script is disabled the validation doesn't worth o...
11 years ago (Mat Patnik)
100%
For a beginner may be hard , but after learning its easy .
11 years ago (Hari K T)
87%
an excellent package, much appreciated
12 years ago (Brian Read)
100%
A very powerful package that incorporates a lot.
12 years ago (Ian Holden)
85%
Great class, easy to use and implement
12 years ago (tovia)
100%
This package is great.
12 years ago (ibo kut)
90%
 

For more information send a message to info at phpclasses dot org.