PHP Classes

Larrys Form Generation: Create HTML forms using jQuery for validation

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in Bookmark in
  Info   View files View files (4)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Last Updated Ratings Unique User Downloads Download Rankings  
2012-05-17 (3 years ago) RSS 2.0 feedNot yet rated by the usersTotal: 602 This week: 2All time: 4,856 This week: 682Up
Version License PHP version Categories  
form-generation 1.0GNU General Publi...5.2HTML
Description Author  

This class can create HTML forms using jQuery for validation.

It can generate HTML for different types of form elements like inputs, labels, form start and end sections.

The generated HTML includes JavaScript that can validate the form inputs either when the inputs are changed or the form is submitted.

The validation can be done according to certain rules and it uses the jQuery JavaScript library and a JavaScript class provided separately.

Picture of Larry Wakeman
Name: Larry Wakeman is available for providing paid consulting. Contact Larry Wakeman .
Classes: 4 packages by
Country: United States United States
Age: ???
All time rank: 1406191 in United States United States
Week rank: 224 Up16 in United States United States Up
Innovation award
Innovation award
Nominee: 2x

Winner: 1x

    This class is used to create html forms with validation.  To use, in the head(html):
<script language="JavaScript" src=""></script>
<script language="JavaScript" src="validation.js"></script>
<script language="JavaScript">
    var valid = new validate();

    To setup the class:
include('formgeneration.php');     // load the class
$vf = new formgeneration('valid');  // The name of the javascript class is passed in
    Check the example index.php for an example of creating a child class that extends this class
    To create the form(html):
<?php echo $vf->open_form()."\n"; ?>

    To close the form:
<?php echo $vf->close_form()."\n"; ?>

    To create a label:
<?php echo $vf->create_label('Name of object', 'Label')."\n"; ?>

    To create a textbox:
<?php echo $vf->create_text('name', 'required')."\n"; ?>

<?php echo $vf->create_textarea('name', 'required', rows, columns)."\n"; ?>

<?php echo $vf->create_Check('name')."\n"; ?>

    Select List:
                $values = array(
                    '' => 'Please Select',
                    '1' => 'Option 1',
                    '2' => 'Option 2',
                    '3' => 'Option 3',
               echo $vf->create_select('name', 'required', $values)."\n";

        Radio button group:
        $values = array(
            'Milk' => 'Milk',
            'Butter' => 'Butter',
            'Cheese' => 'Cheese',
        echo $vf->create_radio_group('name', 'required', $values)."\n"; 

        Post submit processng.
        The set up is the same for the form.  I use the following to redirect back to the input form on a validation error.
    // post submit processing, normally done on thetarget page though one could useredirects
    if (isset($_POST['submit'])) {
        $error = $vf->validate();
        if ($error != '') {
            // do validation error proccessing
            unset ($_POST['submit']); // we don't want this in the post data going back to the original form
<form name="submision_form" id="submision_form" method="POST" action="/">
    <?php echo $vf->savePostGet(); ?>
    <input type="hidden" name="Message" value="<?php echo $error; ?>">
<script type="text/javascript">
    $(document).ready(function() {
            alert ('<?php echo $error; ?>');
            exit; // redirect back to the original page
        } else {
            // Save the data or whatever

  Files folder image Files  
File Role Description
Plain text file formgeneration.php Class formgeneration class file
Accessible without login Plain text file index.php Example Demonstration Script
Accessible without login Plain text file readme.txt Doc. Dovumentation
Accessible without login Plain text file validation.js Data Validation jQuery class

 Version Control Unique User Downloads Download Rankings  
 0%Total:602All time:4,856
 This week:2This week:682Up