Login   Register  
PHP Classes
elePHPant
Icontem

File: index.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Hugo Mastromauro da Silva  >  Moos Validation  >  index.php  >  Download  
File: index.php
Role: Example script
Content type: text/plain
Description: Example of usage
Class: Moos Validation
Validate submitted form values according to rules
Author: By
Last change: Change in the way of purifying string.
Date: 2010-08-25 05:11
Size: 3,203 bytes
 

Contents

Class file image Download
<?php

/** 

* Class MyValidation

* @author Hugo Mastromauro <hugomastromauro@gmail.com>
* @version 0.1 
* @copyright  GPL © 2010, Hugo Mastromauro. 
* @access public  
* @package libraries 
* @subpackage MyValidation
*  
*/

require_once 'MyValidation.php';

$data '';
$error '';

$rules = array( 'name' => 
                    array( 
'label' => 'Name''rules' => 'required:checkName' ),
                
'age' => 
                    array( 
'label' => 'Age''rules' => 'number' ),
                
'birthday' => 
                    array( 
'label' => 'Birthday''rules' => 'date' ),
                
'email' => 
                    array( 
'label' => 'E-mail''rules' => 'email' ),
                
'cpf' => 
                    array( 
'label' => 'CPF''rules' => 'cpf' ),
                
'password' => 
                    array( 
'label' => 'Password''rules' => 'password[6]["passwordcheck"]' ),
                
'passwordcheck' => 
                    array( 
'label' => 'Password check''rules' => 'require' ));
                                    
$messages = array( 'error' => 
                        array( 
'required'     => 'Field %s is empty!',
                                
'number'     => 'Wrong data in field %s!',
                                
'checkName' => 'Name already exists!',
                                
'date'         => '%s date %s not valid!',
                                
'email'     => 'E-mail not valid!',
                                
'password'     => 'Passwords do not match or to short!',
                                
'cpf'         => 'CPF not valid!' ));
    
$val = new MyValidation($rules$messages);
    
if (isset(
$_GET['action']) and $_GET['action'] == 'send') {
    
    if (
$val->validate()){
        
        
$data $val->getAllData();    
        
        echo 
'All data sent!';
        
        echo 
'<pre>';
        
print_r($data);
        echo 
'</pre>'
        
    }else{
        
        
$data $val->getAllData();    
        
$error $val->getAllError();                
    }
}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Moos Validation</title>
<style type="text/css">
    ul {
        list-style-type: none;
        margin: 0;
        padding: 10px;    
        background: #eee
    }
    
    ul li {
        margin: 20px 0;        
    }
</style>
</head>
<body>

<?php 
    
echo '<pre>';
    
print_r($error);
    echo 
'</pre>'
?>

<form action="index.php?action=send" method="post" name="send">
    <ul>
        <li>
            <label>Name: <input type="text" name="name" value="<?php if (isset($data['name'])) echo $data['name']; ?>" /> [hugo]</label>
        </li>
        <li>
            <label>Age: <input type="text" name="age" value="<?php if (isset($data['age'])) echo $data['age']; ?>" /></label>
        </li>
        <li>
            <label>E-mail: <input type="text" name="email" value="<?php if (isset($data['email'])) echo $data['email']; ?>" /></label>
        </li>
        <li>
            <label>Birthday: <input type="text" name="birthday" value="<?php if (isset($data['birthday'])) echo $data['birthday']; ?>" /> [0000-00-00]</label>
        </li>
        <li>
            <label>cpf: <input type="text" name="cpf" value="<?php if (isset($data['cpf'])) echo $data['cpf']; ?>" /></label>
        </li>
        <li>
            <label>Password: <input type="password" name="password" value="" /></label>
        </li>
        <li>
            <label>Password confirm: <input type="password" name="passwordcheck" value="" /></label>
        </li>
        <li>
            <input type="submit" value="send" />
        </li>
    </ul>
</form>

</body>
</html>