]> Dogcows Code - chaz/p5-CGI-Ex/blob - samples/generate_js.pl
CGI::Ex 2.00
[chaz/p5-CGI-Ex] / samples / generate_js.pl
1 #!/usr/bin/perl -w
2
3 use strict;
4 use CGI::Ex::Validate;
5
6 ### sampe
7 my $js_path = "/cgi-bin/js";
8 my $form_name = "my_form";
9 my $val_hash = {
10 'general as_hash_join' => "<br>\n<br>",
11 'general group_order' => [qw(username password)],
12 username => {
13 required => 1,
14 match => 'm/^\w+$/',
15 max_len => 20,
16 },
17 password => {
18 match => ['m/\d/', 'm/[a-z]/'],
19 match_error => "\$name Must contain a letter and a number",
20 },
21 };
22
23
24 ### generate the js
25 my $val_obj = CGI::Ex::Validate->new;
26 my $val = $val_obj->generate_js($val_hash, $form_name, $js_path);
27
28
29 ### sample document out put
30 ### not that you should ever inline your html
31 $val_obj->cgix->content_type;
32 print "<html>
33 <body>
34 <form name='my_form'>
35
36 Username: <input type=text size=20 name=username><br>
37 <span class=error id=username_error></span><br>
38 Password: <input type=text size=20 name=password><br>
39 <span class=error id=password_error></span><br>
40 <input type=submit>
41
42 </form>
43
44 $val
45
46 </body>
47 </html>
48 ";
This page took 0.033055 seconds and 4 git commands to generate.