<?php
 
 
// define the class directory
 
define("CLASS_DIR", "../../../_class/");
 
 
// include section
 
require_once(CLASS_DIR."smarty/Smarty.class.php");
 
require_once("class.validate_form.php");
 
 
// create a new Smarty-object
 
$s = new Smarty;
 
// set the compile directory for Smarty
 
$s->set_compile_dir(CLASS_DIR."smarty/");
 
$s->assign("form_action", $PHP_SELF);
 
 
// the form is submitted
 
if (isset($_POST["is_sent"]) && $_POST["is_sent"] == true)
 
{
 
    // define the required fields in an array
 
    $req_fields = array(
 
        array("fld" => "username",   "msg" => "Please choose in a username."),
 
        array("fld" => "zipcode",    "msg" => "Please fill in your zipcode."),
 
        array("fld" => "email",      "msg" => "Please fill in a emailaddress."),
 
        array("fld" => "gender",     "msg" => "Please fill in your gender."),
 
        array("fld" => "books",      "msg" => "Please choose a book."),
 
        array("fld" => "website",    "msg" => "Please fill in your website."),
 
        array("fld" => "birthdate",  "msg" => "Please fill in your birthdate."),
 
        array("fld" => "date_01_01", "msg" => "Please fill in your day {foo}"),
 
        array("fld" => "date_01_02", "msg" => "Please fill in your month {foo}"),
 
        array("fld" => "date_01_03", "msg" => "Please fill in your year {foo}")
 
    );
 
    
 
    // create a new object
 
    $vf = new validate_form($_POST, $req_fields);
 
    
 
    // set the custom functions
 
    $vf->is_length  ("username",        "The length of your username is not permitted.", 5, 20);
 
    $vf->is_regexp  ("^[a-z0-9_]+$",    "username", "Please make sure your username only contains letters, numbers or a underscore.");
 
    $vf->set_regexp ("url",             "^[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&%\$#\=~])*$");
 
    $vf->is_email   ("email",           "Please fill in a valid emailaddress.");
 
    $vf->is_zipcode ("zipcode",         "Please fill in a valid zipcode.");
 
    $vf->is_url     ("website",         "Please fill in a valid URL.");
 
    $vf->is_date    ("birthdate",       "Please fill in your birthdate correctly.");
 
    
 
    // define custom date
 
    $vf->set_date   ("date_01_01", "date_01_02", "date_01_03", "/");
 
    $vf->is_date    ("custom_date",     "Please fill in a correct date.", "mm-dd-yyyy");
 
    
 
    // activate debugging
 
    $vf->set_debugging();
 
    
 
    if ($vf->is_valid())
 
    {
 
        echo "<P>-submit form!-\n";
 
    }
 
    
 
    foreach ($_POST as $key=>$value)
 
    {
 
        $s->assign($key, $value);
 
    }
 
}
 
 
$s->display("form.tpl.php");
 
 
?>
 
 |