PHP:Form Demo 2

A simple form as well, except this time there are more advanced validators.

Name:
E-mail:

Date (DD/MM/YY):
EnterID:

Source:

<?php
include ('../../libs/phpform.php');
?>
<html>
    <head><title>PHP:Form Demo 2</title></head>

    <body>
        <h1>PHP:Form Demo 2</h1>
        <p>A simple form as well, except this time there are more advanced validators.</p>

        <validator form="demo1" for="name" callback="is_vip"><strong>Hold it right there buddy. You're not in the VIP list. Only Dennis, John, Chris and Jeremy are.</strong></validator>

        <php:form name="demo1">
            Name: <input type="text" name="name" />
            <validator for="name" required="true">Please enter your name.</validator>
            <br />

            E-mail: <input type="text" name="email" />
            <validator for="email" required="true">Please enter your e-mail address</validator><br /><br />

            Date (DD/MM/YY): <input type="text" name="date" />
            <validator for="date" regex="/\d{2}\/\d{2}\/\d{2}$/">Please enter a date, in the correct format (DD/MM/YY)</validator>
            <br />

            EnterID: <input type="text" name="enterid" />
            <validator for="enterid" numeric="true">Please enter a valid (numeric) EnterID.</validator>
            <br />

            <input type="submit" name="submit" value="Enter Secure Area" />
        </php:form>

        <?php
            
// Does the form validate?
            
if (!$_FORMS->validate('demo1')) {
                
// Display form
                
$_FORMS->display('demo1');
            } else {
                
// Print POST variables
                
echo '<pre>';
                
print_r ($_POST);
                echo 
'</pre>';
            }

            
// Callback function for a validator
            
function is_vip ($str) {
                
// Check if str is in VIP list
                
if (!in_array($str, array('Dennis''John''Chris''Jeremy'))) {
                    return 
false;
                } else {
                    return 
true;
                }
            }

            
// Show source (only for demo purposes)
            
echo '<h2>Source: </h2>';
            
highlight_file (__FILE__);
        
?>

    </body>
</html>