forked from ASoares/PHP-Form-Validation
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
78 lines (60 loc) · 1.93 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
index.php has a typical example , if anyone decides to use this , please check the spelling on error messages ;-)
/**
*
* ValidFluent
*
* A simple, flexible and easy to use PHP form validation class
* (uses a fluent interface )
*
* @author Andre Soares
*
* typical use:
$valid = new ValidFluent($_POST);
$valid->name('user_name')->required('You must chose a user name!')->alfa()->minSize(5);
$valid->name('user_email')->required()->email();
$valid->name('birthdate')->date('please enter date in YYYY-MM-DD format');
if ($valid->isGroupValid())
echo 'Validation Passed!';
* //////////////////////////////////////
* OR
*
$valid = new ValidFluent($_POST);
if ( $valid->name('user_name')->required('You must chose a user name!')->alfa()->minSize(5)
->name('user_email')->required()->email()
->name('birthdate')->date('please enter date in YYYY-MM-DD format')
->isGroupValid() )
echo 'Validation passed!';
* //////////////////////////////////////////////////////////////////
* On HTML
<form method="POST">
<input type="text" name="email"
value="<?php echo $valid->getValue('email'); ?>" />
<span class="error">
<?php echo $valid->getError('email'); ?>
</span>
...
...
* ///////////////////////////////////////////////////////////////////
* To create new validation rules!
#1 define default error message
private static $error_myValidaton = 'my default error message';
#2 create new validation function
function myValidation($param , $errorMsg=NULL)
{
if ($this->isValid && (! empty($this->currentObj->value)))
{
//
//code to check if validation pass
//
$this->isValid = // TRUE or FALSE ;
if (! $this->isValid)
$this->setErrorMsg($errorMsg, self::$error_myValidation, $param);
}
return $this;
}
#3 use it
$Valid->name('testing')->myValidation(10, 'some error msg!');
*
*
*/