PHP Classes

File: example3.php

Recommend this page to a friend!
  Classes of Fransjo Leihitu  >  LiveValidationPHP  >  example3.php  >  Download  
File: example3.php
Role: Example script
Content type: text/plain
Description: Example 3
Class: LiveValidationPHP
Validate forms on the browser and server side
Author: By
Last change:
Date: 14 years ago
Size: 5,974 bytes
 

Contents

Class file image Download
<?php
   
include("livevalidationphp.class.php"); // the LiveValidationPHP scripts
   
include("rules.inc.php"); // hold the rules
   
   
$html="";
   
$frmTestLive=new LiveValidationMassValidatePHP("frmTest",$_POST);
   
$frmTestLive->addRules($formRules["frmTest"]);
   
$html=$frmTestLive->generateAll();

   
// check for a post action
   
$frmTestErrors=array();
    if(isSet(
$_POST["action"]))
    {
        if(
$_POST["action"]=="send_test_form")
        {
           
$frmTestErrors=$frmTestLive->validate();
        }
    }
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
        <title>LiveValidationPHP | Example 3</title>
       
        <link href="livevalidation/livevalidation.css" rel="stylesheet" type="text/css" media="screen">
        <script language="javascript" type="text/javascript" src="livevalidation/livevalidation.js"></script>
    </head>

    <body>
   
    <h1>Example 3</h1>
   
    <p>To submit this form, you need to validate this.</p>
   
    <?php
       
if(count($frmTestErrors)>0)
        {
            print
"<strong>You have errors:</strong>";
            print
"<pre>";
           
print_r($frmTestErrors);
            print
"</pre>";
        }
   
?>

    <form name='frmTest' id='frmTest' action='' method='post'>
   
        <input type='hidden' name='action' value='send_test_form'>
   
        <h2>Presence</h2>
        <p>
            Enter the field then click somewhere else<br>
            <input type='text' name='element_1' id='element_1' value=''>
        </p>
       
        <hr><h2>Format</h2>
        <p>
            Should contain the phrase 'live' in any case:<br>
            <input type='text' name='element_2' id='element_2' value=''>
        </p>
       
        <hr><h2>Numericality</h2>
       
        <strong>Basic</strong>
        <p>
            Should be a number:<br>
            <input type='text' name='element_3' id='element_3' value=''>
        </p>
       
        <strong>Only allow integers</strong>
        <p>
            Should be an integer:<br>
            <input type='text' name='element_4' id='element_4' value=''>
        </p>
       
        <strong>Specific number</strong>
        <p>
            Should be 2000 (or scientific representation of it, 2e3):<br>
            <input type='text' name='element_5' id='element_5' value=''>
        </p>
       
        <strong>Higher than or equal to a minimum number</strong>
        <p>
            Should be 2000 or higher (or scientific representation of it, 2e3):<br>
            <input type='text' name='element_6' id='element_6' value=''>
        </p>
       
        <strong>Lower than or equal to a maximum number</strong>
        <p>
            Should be 2000 or lower (or scientific representation of it, 2e3):<br>
            <input type='text' name='element_7' id='element_7' value=''>
        </p>
       
        <strong>Within a range of numbers</strong>
        <p>
            Should be between 2000 and 2003:<br>
            <input type='text' name='element_8' id='element_8' value=''>
        </p>
       
        <strong>Combination</strong>
        <p>
            Should be between 2000 and 2003, and also be an integer:<br>
            <input type='text' name='element_9' id='element_9' value=''>
        </p>
       
       
       
        <hr><h2>Length</h2>
       
        <strong>Specific length</strong>
        <p>
            Should be 4 characters in length:<br>
            <input type='text' name='element_10' id='element_10' value=''>
        </p>
       
        <strong>Longer than or equal to a minimum length</strong>
        <p>
            Should be 4 or more characters in length:<br>
            <input type='text' name='element_11' id='element_11' value=''>
        </p>
       
        <strong>Shorter than or equal to a maximum length</strong>
        <p>
            Should be 4 or less characters in length:<br>
            <input type='text' name='element_12' id='element_12' value=''>
        </p>
       
        <strong>Within a range of lengths</strong>
        <p>
            Should be between 4 and 8 characters in length:<br>
            <input type='text' name='element_13' id='element_13' value=''>
        </p>
       
       
        <hr><h2>Inclusion</h2>
       
        <strong>Exact match</strong>
        <p>
            Should be "cow", "pigeon", or "giraffe": <br>
            <input type='text' name='element_14' id='element_14' value=''>
        </p>
       
        <strong>Partial match</strong>
        <p>
            Should contain "cow", "pigeon", or "giraffe" somewhere in your entry: <br>
            <input type='text' name='element_15' id='element_15' value=''>
        </p>
       
       
       
        <hr><h2>Exclusion</h2>
       
        <strong>Exact match</strong>
        <p>
            Should not be "cow", "pigeon", or "giraffe":<br>
            <input type='text' name='element_16' id='element_16' value=''>
        </p>
       
        <strong>Partial match</strong>
        <p>
            Should not contain "cow", "pigeon", or "giraffe" anywhere in your entry<br>
            <input type='text' name='element_17' id='element_17' value=''>
        </p>
       
       
        <hr><h2>Acceptance</h2>
       
        <p>
            I accept that LiveValidation is the validation of my dreams:<br>
            <input type='checkbox' name='element_18' id='element_18' value='ok'>
        </p>
       
       
       
        <hr><h2>Confirmation</h2>
        <p>
            Enter a password:<br>
            <input type='password' name='myPasswordField' id='myPasswordField' value=''>
        </p>
       
        <p>
            Confirm password:<br>
            <input type='password' name='element_19' id='element_19' value=''>
        </p>
       
       
        <hr><h2>Email</h2>
        <p>
            Should be an email address:<br>
            <input type='text' name='element_20' id='element_20' value=''>
        </p>
       
        <hr><h2>onlyOnBlur</h2>
        <p>
            Must be filled in: <br>
            <input type='text' name='element_21' id='element_21' value=''>
        </p>
       
        <hr><h2>wait</h2>
        <p>
            Required, and at least 10 characters (validation starts after 300ms): <br>
            <input type='text' name='element_22' id='element_22' value=''>
        </p>
       
       
        <hr><h2>Selectbox</h2>
        <select id="element_23" name="element_23">
            <option value="Please select..." selected="selected">Please select...</option>
            <option value="Live">Live</option>
            <option value="Validation">Validation</option>
        </select>
       

        <p>
            <input type='submit' value='go'>
        </p>
    </form>
   
    <script>
        <?php
           
print $html;
       
?>
</script>
   
    </body>
</html>

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