PHP Classes
elePHPant
Icontem

File: classes/register.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of johno dread  >  Custom Form Validation  >  classes/register.php  >  Download  
File: classes/register.php
Role: Example script
Content type: text/plain
Description: Demonstrates validating all fields on a registration form
Class: Custom Form Validation
Validate form values according to several rules
Author: By
Last change:
Date: 5 years ago
Size: 2,781 bytes
 

Contents

Class file image Download
<?php

/**
 * @copyright 2010
 */


session_start();

require_once(
'validation.php');
$valid = new validation;

if( isset(
$_POST) && count($_POST) > 0)
{
   
   
// set error messages for specific fields
   
$valid->custom_err("fname","Your full name is required.");
   
$valid->custom_err("lname","Your full name is required.");
   
$valid->custom_err("email","Please enter a valid email.");
   
$valid->custom_err("birthday_year","Your full birthdate is required.");
   
$valid->custom_err("birthday_day","Your full birthdate is required.");
   
$valid->custom_err("birthday_month","Your full birthdate is required.");
   
$valid->custom_err("zip","At least 5 digits are required.");
   
$valid->custom_err("city","At least 4 characters are required.");
   
$valid->custom_err("username","At least 5 characcters are required.");

    
// set custom errors for validation functions
   
$valid->custom_err('alpha_chars',"field contains invalid characters.");
   
$valid->check("email2","is_email|matches[email]|required");
   
   
   
// now proceed to check your fields
   
$valid->check("fname","required|xss_clean");//alpha_chars|min_length[2]|required|
   
$valid->check("mname","alpha_chars");
   
$valid->check("lname","alpha_chars|min_length[2]|required");
   
$valid->check("username","alpha_numeric|min_length[7]|required");
   
   
$valid->check("birthday_year","required");
   
   
$valid->check("birthday_day","required");
   
$valid->check("birthday_month","required");
   
$valid->check("state","required");
   
   
$valid->check("password","required");
   
$valid->check("confirm","required");
   
   
           
   
$valid->check("email","is_email|matches[email2]|required");
   
$valid->check("email2","is_email|matches[email]|required");
   
$valid->check("pri_phone","alpha_dash|min_length[10]");
   
   
$valid->check("mname","alpha_chars");
       
   
$valid->check("sec_phone","alpha_dash|min_length[10]");
   
$valid->check("zip","is_natural|exact_length[5]|required");
   
$valid->check("address","alpha_numeric|required");
   
$valid->check("city","alpha|min_length[4]|required"); //birthday_year
   
       
       
$_SESION['failed_array'] = $valid->failed_array;
               
 
// if valid == true; connect and insert/update
    
if(count($valid->failed_array) < 1)
    {
        echo
"<b>Congratulations: you are currently signed in.";
        echo
"<pre>";
       
print_r($valid->failed_array);
        echo
"</pre>";
       
    }
}
echo
"<pre>";
       
print_r($_POST);
        echo
"</pre>";

?>

<style>
hr
{
    color:#CCC;
    height: 1px;
    margin-top:0px;
}
#topnav
{
    float: right;
}
</style>


<h1 style='color:#2F8B1E;font-family:arial;margin-bottom:0px;'>Sample Registration </h1><hr />
 

 <span>Fields marked with(*) are required.</span>
<?php

//$error = $register->the_msg;

include("../forms/user_profile.php");
?>