PHP Classes

File: index.php

Recommend this page to a friend!
  Classes of Nahid Bin Azhar   CS form validator   index.php   Download  
File: index.php
Role: Unit test script
Content type: text/plain
Description: Unit test script
Class: CS form validator
Validate submitted form values in multiple ways
Author: By
Last change:
Date: 9 years ago
Size: 611 bytes
 

Contents

Class file image Download
<form action="" method="post">
    <input type="text" name="email">
    <input type="text" name="website">
    <input type="text" name="dob">
    <input type="text" name="gender">
    <input type="submit" name="submit" value="Submit">
</form>

<?php

require_once "validator.php";


$rules=[
   
'email'=>'required&email',
   
'website'=>'url',
   
'dob'=>'required&numeric&min:2',
   
'gender'=>'required&in:male,female'
];

$msg=[
   
'website'=>[
       
'url'=>'Sorry this not a valid url'
   
]
];



$valid=Validator::validate($_POST, $rules);

if(
$valid->hasErrors()){
    foreach (
$valid->errorsAll() as $err) {
        echo
'<li>'.$err.'</li>';
    }
}