<?php
# Version 1.0
require_once('../include/config.inc.php');
// Create object
$f = new form_handle();
# Notes:
# What is nice about this class is that you can still view form elements in design
# view and be able to drag and move them around in editors
# A reference is the name of the index in the array that holds error messages
# The refernece will be your error call back message
# References hold error messages from failed validation
# Example:
# Validation Rule:
# array('LENMIN','minfirstname','f_name','2','not enough chars'),
# echo $f->getError('minfirstname'); -- will output "not enough chars"
# This is for server side error messages being redisplayed.
# Javascript errors popup an alert window automatically
// Set allowed methods
// ('POST') ('GET') ('POST,GET')
$f->allowMethod('POST');
// Use JS validation in addition to serverside
$f->useJS();
#------------------------------------------------------------------------------------
# + Validation rules +
#------------------------------------------------------------------------------------
$f->validate
(array
(
// Validation will only be preformed on fields that have a value
// If you wish the field to be required on top of validation use 'REQ'
// Minimum character length required if value was submitted
// TYPE, Reference, Form Field Name, Min Length, Error Message
array('LENMIN','f_name','f_name','2','not enough chars'),
// Character length must be less then of equal to value set
// TYPE, Reference, Form Field Name, Max Length, Error Message
array('LENMAX','password','password1','20','too many chars'),
// Require a value be entered into field or radio/checkbox/dropdown be selected
// TYPE, Reference, Form Field Name, Error Message
array('REQ','password','password1','password Required'),
// Require field type to match a validation rule
// These are like predefined regular expressions for common validation types
// Avaliable types:
// email, phone, zip, date, :: date mm/dd/yyyy m/d/yyyy or mm/d/yyyy or m/dd/yyyy
// int, numeric, float, bool,
// alpha, alphint, alphanumeric,
// alpa_, alphaint_, alphanumeric_, :: + underscore
// alpa_s, alphaint_s, alphanumeric_s, :: + space and underscore
// TYPE, What Type, Reference, Form Field Name, Error Message
array('TYPE','email','email','email1','Must be email'),
// Verify a credit card number based on type of card
// Avaliable types:
// Visa, MasterCard, DinersClub, CarteBlanche,
// AmericanExpress, Discover, JCB, Enroute
// TYPE, Reference, Form Field Name Card #, Form Field Name Card Type, Error Message
array('CC','creditcard','cardnumber','cardtype','Invalid Credit Card Number'),
// Require to submitted fields be the same value
// TYPE, Reference, Form Field Name1, Form Field Name2, Error Message
array('EQ','password','password1','password2','Not the same passwords!'),
// Validate against a user defined regular express case sensitive
// TYPE, Regular Expression (case sensitive), Reference, Form Field Name, Error Message
array('R','^[A-Z]','ref1','field1','Invalid value'),
// Validate against a user defined regular express case insensitive
// TYPE, Regular Expression (case insensitive), Reference, Form Field Name, Error Message
array('RI','^[A-Z]','ref2','field2','Invalid value'),
// Duplicate entry in database throws an ERROR
// TYPE, Reference, QUERY, Error Message
array('DUP1','login',"SELECT user_login FROM user WHERE login = '{$f->method['login']}' LIMIT 1",'User Name Already Taken'),
// NO Duplicate entry in database throws an ERROR
// TYPE, Reference, QUERY, Error Message
array('DUP2','login',"SELECT user_login FROM user WHERE login = '{$f->method['login']}' LIMIT 1",'User Name Must Allready Be In Database'),
)
);
#------------------------------------------------------------------------------------
# - Validation rules -
#------------------------------------------------------------------------------------
// Clean all posted values via the method submitted GET or POST
$f->stripAll();
// If you need to pass validation for any reason even if above validation failed
$f->forcePass();
// If you need to fail the validation for any reason (maybe a custom validation mehtod you created)
$f->forceFail('reference');
if(isset($_POST['wassent']))
{
// Check to see if validation passed
if($f->pass())
echo 'Validation Passed';
else
echo 'Validation Failed';
// If you just want to do a DB query on validation pass then you can use
// The SQL being passed into the function will only execute of validation passed
$f->queryOnPass('SQL QUERY');
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Form Handle</title>
<?php
// If you are using javascript validation echo the js validation here
if(isset($f)) $f->displayJS();
?>
</head>
<body>
<?php
// Return ALL/if any errors that were generated during the validation process
// $seperate 0 = <br /> *also default
// $seperate 1 = <br /><br />
// $seperate 2 = <p>$message</p>
// $seperate 3 = <span class="$style_class">$message</span>
// $seperate 4 = <div class="$style_class">$message</div>
echo $f->getErrorBlob(4,'error');
?>
<form action="<?php echo $_SERVER["PHP_SELF"];?>" method="post"
enctype="multipart/form-data" name="form"
<?php
// If you are using javascript validation have the form call it on submit
if(isset($f) && !empty($f->js)) echo 'onSubmit="javascript: return validateForm(this)"';
?>>
<p>First Name
<input type="text" size="20" maxlength="20" <?php echo $f->setText('f_name'); ?> />
<?php echo $f->getError('f_name'); ?> </p>
<p>Last Name
<input type="text" size="20" maxlength="20" <?php echo $f->setText('l_name'); ?> />
<?php echo $f->getError('l_name'); ?> </p>
<p>Login Name
<input type="text" size="20" maxlength="20" <?php echo $f->setText('login'); ?> />
<?php echo $f->getError('login'); ?> </p>
<p>Password
<input name="password1" type="password" size="20" id="password1" maxlength="20" />
<?php echo $f->getError('password'); ?></p>
<p> Retype Password
<input name="password2" type="password" size="20" id="password2" maxlength="20" />
</p>
<p>E-Mail
<input type="text" size="20" maxlength="100" <?php echo $f->setText('email1'); ?> />
<?php echo $f->getError('email'); ?> </p>
<p>Retype E-Mail
<input type="text" size="20" maxlength="100" <?php echo $f->setText('email2'); ?> />
</p>
<p>
1
<input type="checkbox" value="checkbox" <?php echo $f->setCheckBox('check1'); ?>/>
2
<input type="checkbox" value="checkbox" <?php echo $f->setCheckBox('check2'); ?>/>
3
<input type="checkbox" value="checkbox" <?php echo $f->setCheckBox('check3'); ?>/>
</p>
<p>
1
<input type="radio" <?php echo $f->setRadio('rad',1); ?>/>
2
<input type="radio" <?php echo $f->setRadio('rad',2); ?>/>
3
<input type="radio" <?php echo $f->setRadio('rad',3); ?>/>
</p>
<p>
<select name="selectme">
<option <?php echo $f->setList('selectme','val1'); ?>>Value 1</option>
<option <?php echo $f->setList('selectme','val2'); ?>>Value 2</option>
<option <?php echo $f->setList('selectme','val3'); ?>>Value 3</option>
</select>
</p>
<p>
<select name="mult[]" multiple="multiple">
<option <?php echo $f->setList('mult[]','val1',0,1); ?>>Value 1</option>
<option <?php echo $f->setList('mult[]','val2',0,1); ?>>Value 2</option>
<option <?php echo $f->setList('mult[]','val3',0,1); ?>>Value 3</option>
</select>
</p>
<p>
<textarea name="text1"><?php echo $f->setTextArea('text1'); ?></textarea>
</p>
<p>
<input type="hidden" name="wassent" value="1" />
<input alt="Submit Me" title="Submt Me!" type="submit" name="Create_User" value="Submit" />
<input type="reset" name="Submit2" value="Reset" />
</p>
</form>
</body>
</html>
|