Login   Register  
PHP Classes
elePHPant
Icontem

File: valtest.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Brett Dutton  >  Validator  >  valtest.php  >  Download  
File: valtest.php
Role: Example script
Content type: text/plain
Description: Test implementation of Validator Class
Class: Validator
Extensible Dynamic Javascript Validator
Author: By
Last change: Added new "Non Existant" form variable name to test the new feature of the Validator class that checks the existance of a form variable in JavaScript
Date: 11 years ago
Size: 2,078 bytes
 

Contents

Class file image Download
<html>
<head>
<title>Validator Test Program</TITLE>
</head>
<BODY>
<?
// Just display the form variables
foreach ( $_POST as $key => $val ) {
    echo ( 
"<br>POST: key=$key value=$val);
}
?>



<?
require_once ( "Validator.php" );
$valid = new Validator "USEREDIT" );
$valid->addExists "fldFirstName""First Name" );
$valid->addExists "fldLastName",  "Last Name" );
$valid->addExists "fldEmail",     "Email" );
$valid->addEmail  "fldEmail" );
$valid->addCopy   "fldFirstName""fldPreferedName" );
$valid->addExists "fldPassword",  "Password must exist" );
$valid->addEqual  "fldPassword",  "fldPassword_CHK""Passwords must be the same" );

// This form var does not exist
$valid->addExists "nonExistFormVar",  "NonExist" );

// Add this if you want to be alerted to missing form variables
// probably good for a debug mode
//$valid->setMissingAlert ( TRUE ); 

echo $valid->toHtml ();
?>

<form name="USEREDIT" action="valtest.php" method="post">
  <table border=1 cellspacing=0 cellpadding=0>
    <TR>
      <TD nowrap >First Name</TD>
      <TD><input type="text" name="fldFirstName"></TD>
    </TR>
    <TR>
      <TD nowrap >Last Name</TD>
      <TD><input type="text" name="fldLastName"></TD>
    </TR>
    <TR>
      <TD nowrap >Prefered Name</TD>
      <TD><input type="text" name="fldPreferedName"></TD>
    </TR>
    <TR>
      <TD nowrap >Email</TD>
      <TD><input type="text" name="fldEmail"></TD>
    </TR>
    <TR>
      <TD colspan=2>
        Note: Passwords here should be type <i>password</i> but for this example just text will do
      </TD>
    </TR>
    <TR>
      <TD nowrap >Password</TD>
      <TD><input type="text" name="fldPassword"></TD>
    </TR>
    <TR>
      <TD nowrap >Reenter Password</TD>
      <TD><input type="text" name="fldPassword_CHK"></TD>
    </TR>
    <TR>
      <TD colspan=2>
        <input type="submit" name="UserEdit_Action" value="Update" <? echo $valid->onSubmit(); ?>>
      </TD>
    </TR>
  </table>
</form>
</BODY>
<html>