| 1 |
<html> |
| 2 |
<head> |
| 3 |
<title>Embperl Example - Input Form Validation</title> |
| 4 |
|
| 5 |
[- |
| 6 |
|
| 7 |
use Embperl::Form::Validate ; |
| 8 |
|
| 9 |
$epf = Embperl::Form::Validate -> new ( |
| 10 |
[ |
| 11 |
[ |
| 12 |
-key => 'name', |
| 13 |
-name => 'Name', |
| 14 |
required => 1, |
| 15 |
length_min => 4, |
| 16 |
], |
| 17 |
[ |
| 18 |
-key => 'id', |
| 19 |
-name => 'Id', |
| 20 |
-type => 'Number', |
| 21 |
gt => 0, |
| 22 |
lt => 10, |
| 23 |
], |
| 24 |
[ |
| 25 |
-key => 'email', |
| 26 |
-msg => 'This is not a valid E-Mail address', |
| 27 |
must_contain_one_of => '@.', |
| 28 |
matches_regex => '..+@..+\\...+', |
| 29 |
length_min => 8, |
| 30 |
], |
| 31 |
[ |
| 32 |
-key => 'msg', |
| 33 |
-name => 'Message', |
| 34 |
emptyok => 1, |
| 35 |
length_min => 10, |
| 36 |
] |
| 37 |
]) ; |
| 38 |
|
| 39 |
if ($fdat{check}) |
| 40 |
{ |
| 41 |
$errors = $epf -> validate_messages ; |
| 42 |
} |
| 43 |
|
| 44 |
-] |
| 45 |
<script> |
| 46 |
[+ do { local $escmode = 0 ; $epf -> get_script_code } +] |
| 47 |
</script> |
| 48 |
|
| 49 |
|
| 50 |
</head> |
| 51 |
<body> |
| 52 |
|
| 53 |
<h1>Embperl Example - Input Form Validation</h1> |
| 54 |
|
| 55 |
|
| 56 |
This example simply validates the form input when you hit submit. |
| 57 |
If your input is correct, the form is redisplay with your input, |
| 58 |
otherwise the error message is shown. If you turn off JavaScript |
| 59 |
the validation is still done one the server-side. Any validation |
| 60 |
for which no JavaScript validation is defined (like regex matches), |
| 61 |
only the server-side validation is performed. |
| 62 |
|
| 63 |
|
| 64 |
<hr> |
| 65 |
|
| 66 |
[$if @$errors $] |
| 67 |
<h3>Please correct the following errors</h3> |
| 68 |
[$foreach $e (@$errors)$] |
| 69 |
<font color="red">[+ $e +]</font><br> |
| 70 |
[$endforeach$] |
| 71 |
[$else$] |
| 72 |
<h3>Please enter your data</h3> |
| 73 |
[$endif$] |
| 74 |
|
| 75 |
<form action="formvalidation.htm" method="GET" onSubmit="return epform_validate_forms_0_()"> |
| 76 |
<table> |
| 77 |
<tr><td><b>Name</b></td> <td><input type="text" name="name"></td></tr> |
| 78 |
<tr><td><b>Id (1-9)</b></td> <td><input type="text" name="id"></td></tr> |
| 79 |
<tr><td><b>E-Mail</b></td> <td><input type="text" name="email"></td></tr> |
| 80 |
<tr><td><b>Message</b></td> <td><input type="text" name="msg"></td></tr> |
| 81 |
<tr><td colspan=2><input type="submit" name="check" value="send"></td></tr> |
| 82 |
</table> |
| 83 |
</form> |
| 84 |
|
| 85 |
|
| 86 |
<p><hr> |
| 87 |
|
| 88 |
<small>Embperl (c) 1997-2005 G.Richter / ecos gmbh <a href="http://www.ecos.de">www.ecos.de</a></small> |
| 89 |
|
| 90 |
</body> |
| 91 |
</html> |