]> Dogcows Code - chaz/p5-CGI-Ex/blob - samples/cgi_ex_2.cgi
CGI::Ex 2.00
[chaz/p5-CGI-Ex] / samples / cgi_ex_2.cgi
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 cgi_ex_2.cgi - Rewrite of cgi_ex_1.cgi using CGI::Ex::App
6
7 =cut
8
9 if (__FILE__ eq $0) {
10 handler();
11 }
12
13 sub handler {
14 MyCGI->navigate;
15 }
16
17 ###----------------------------------------------------------------###
18
19 package MyCGI;
20
21 use strict;
22 use base CGI::Ex::App;
23 use CGI::Ex::Dump qw(debug);
24
25 sub pre_loop {
26 my $self = shift;
27 my $path = shift;
28 if ($#$path == -1) {
29 push @$path, 'userinfo';
30 }
31 }
32
33 ### this will work for both userinfo_hash_common and success_hash_common
34 sub hash_common {
35 my $self = shift;
36 return {
37 title => 'My Application',
38 script => $ENV{SCRIPT_NAME},
39 color => ['#ccf', '#aaf'],
40 history => $self->history,
41 }
42 }
43
44 sub ready_validate {
45 my $self = shift;
46 return $self->form->{processing} ? 1 : 0;
47 }
48
49 ###----------------------------------------------------------------###
50
51 sub userinfo_hash_validation {
52 return {
53 'group order' => ['username', 'password'],
54 username => {
55 required => 1,
56 min_len => 3,
57 max_len => 30,
58 match => 'm/^\w+$/',
59 # could probably all be done with match => 'm/^\w{3,30}$/'
60 },
61 password => {
62 required => 1,
63 max_len => 20,
64 },
65 password_verify => {
66 validate_if => 'password',
67 equals => 'password',
68 },
69 };
70 }
71
72 sub userinfo_hash_swap {
73 my $self = shift;
74 my $hash = $self->form;
75 $hash->{form_name} = 'formfoo';
76 $hash->{js_val} = $self->vob->generate_js($self->userinfo_hash_validation(),
77 $hash->{form_name},
78 "$ENV{SCRIPT_NAME}/js");
79 return $hash;
80 }
81
82 ###----------------------------------------------------------------###
83
84 sub userinfo_file_print {
85 return \ qq {
86 <html>
87 <head>
88 <title>[% title %]</title>
89 <style>
90 .error {
91 display: block;
92 color: red;
93 font-weight: bold;
94 }
95 </style>
96 </head>
97 <body>
98 <h1 style='color:blue'>Please Enter information</h1>
99 <span style='color:red'>[% error_header %]</span>
100 <br>
101
102 <form name="[% form_name %]">
103 <input type=hidden name=processing value=1>
104
105 <table>
106 <tr bgcolor=[% color.0 %]>
107 <td>Username:</td>
108 <td>
109 <input type=text size=30 name=username>
110 <span class=error id=username_error>[% username_error %]</span></td>
111 </tr>
112 <tr bgcolor=[% color.1 %]>
113 <td>Password:</td>
114 <td><input type=password size=20 name=password>
115 <span class=error id=password_error>[% password_error %]</span></td>
116 </tr>
117 <tr bgcolor=[% color.0 %]>
118 <td>Password Verify:</td>
119 <td><input type=password size=20 name=password_verify>
120 <span class=error id=password_verify_error>[% password_verify_error %]</span></td>
121 </tr>
122 <tr bgcolor=[% color.1 %]>
123 <td colspan=2 align=right><input type=submit value=Submit></td>
124 </tr>
125
126 </table>
127
128 </form>
129
130 [% js_validation %]
131 </body>
132 </html>
133 };
134 }
135
136 sub success_file_print {
137 return \ qq{
138 <html>
139 <head><title>[% title %]</title></head>
140 <body>
141 <h1 style='color:green'>Success</h1>
142 <br>
143 print "I can now continue on with the rest of my script!";
144 </body>
145 </html>
146 };
147 }
148
149
150 1;
This page took 0.038245 seconds and 4 git commands to generate.