Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Dynamic Language questions

by Rhandom (Curate)
on May 14, 2007 at 15:52 UTC ( [id://615370]=note: print w/replies, xml ) Need Help??


in reply to Dynamic Language questions

Here is another sample using CGI::Ex::App. It behaves identical to the examples the OP provided in the tarbar. There is very little actual code to be written - and if we wanted to take it further we could move the validation and stick it out in a yaml file, and we could take the template and stick it out in a .html template file. Then the CGI would be really short. It can be viewed at http://iterpret.com/cgi-bin/perlmonks_615215.pl.
#!/usr/bin/perl use warnings; use strict; use base qw(CGI::Ex::App); __PACKAGE__->navigate; sub main_hash_validation { return { 'group no_alert' => 1, 'group no_confirm' => 1, member_type => {required => 1}, member_name => {required => 1}, member_address => {required => 1}, company_size => {required => 1}, member_phone => { required => 1, match => 'm/^\(\d{3}\) \d{3}\-\d{4}$/', match_error => 'Please type the phone number in (888) 555- +1234 format', }, }; }; sub main_finalize { my $self = shift; $self->add_to_swap(it_validates => 1); return 0; } sub main_file_print { return \ <<'DOC'; <html> <style>span {color:red}</style> <head> <title>FormWireframe</title> </head> <body> <h2>Simple Form Wireframe</h2> <blockquote> <form method=post name=[% form_name %]> <table> <tr> <td align=left valign=top colspan=2> <h3>Add/edit member</h3> </td> </tr> <tr> <td align=left valign=top colspan=2> <h4><font color=red>*required fields</font></h4> </td> </tr> <tr> <td align=left valign=top> Member Type* </td> <td align=left valign=top> <input type=radio name=member_type value=organization> Organization <input type=radio name=member_type value=individual> Individual <span id=member_type_error>[% member_type_error %]</span> </td> </tr> <tr> <td align=left valign=top> Member Name* </td> <td align=left valign=top> <input type=text size=30 name=member_name> <span id=member_name_error> +[% member_name_error %]</span> </td> </tr> <tr> <td align=left valign=top> Member Address* </td> <td align=left valign=top> <textarea name=member_address rows=4 cols=30></textarea> <span id=memb +er_address_error>[% member_address_error %]</span> </td> </tr> <tr> <td align=left valign=top> Phone* </td> <td align=left valign=top> <input type=text size=20 name=member_phone> <span id=member_phone_erro +r>[% member_phone_error %]</span> </td> </tr> <tr> <td align=left valign=top> Company Size* </td> <td align=left valign=top> <select name=company_size> <option></option> <option>Over 20,000</option> <option>Over 10,000</option> <option>Over 5,000</option> <option>Over 1,000</option> <option>Under 1,000</option> </select> <span id=company_size_error>[% company_size_error %]</span> </td> </tr> <tr> <td align=center valign=top colspan=2> <input type=submit name=submit value=Submit> </td> </tr> </table> </form> [% js_validation %] </blockquote> [% IF it_validates %] <h2>Congrats! This form validates completely!</h2> [% END %] <a href=[% script_name %]/source>Source for this file</a> | <a href=ht +tp://perlmonks.org/?node_id=615215>Perlmonk node 615215</a> </body> </html> DOC } sub source_run_step { shift->cgix->print_content_type('text/plain'); open(my $fh, "<", __FILE__) || die; print <$fh>; return 1; }


my @a=qw(random brilliant braindead); print $a[rand(@a)];

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://615370]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-20 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found