Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Generalising Forms from CGI.pm

by pfaut (Priest)
on Feb 19, 2003 at 02:28 UTC ( #236500=note: print w/ replies, xml ) Need Help??


in reply to Generalising Forms from CGI.pm

Your use of a hash to define your fields leaves a bit of a dilemma: you never know what order they will be in when you invoke keys. This means you have given perl control over the order the fields appear in the form. You'd be better off using an array.

Instead of storing the field type, store a code reference to a subroutine that can generate that type of tag. The sub can take arguments to control creation of the input field.

use CGI qw(:standard); sub TEXTFIELD { my ($name,$siz,$max)=@_; $siz ||= 50; $max ||= 80; return textfield(-name=>$name,-size=>$siz,-maxlength=>$max); } sub TEXTAREA { ...generate a textarea... }; sub SUBMIT { ...generate a submit button... }; my @fields = ( { type=>\&TEXTFIELD, args=>['name'] }, { type=>\&TEXTFIELD, args=>['email'] }, { type=>\&TEXTFIELD, args=>['site name'] }, { type=>\&TEXTFIELD, args=>['description'] }, { type=>\TEXTAREA, args=>['comments'] }, ); my @rows; for (@fields) { my $control = $_->{type}->(@{$_->{args}}); push @rows,td({-align=>left,-valign=>TOP},$control); }
--- print map { my ($m)=1<<hex($_)&11?' ':''; $m.=substr('AHJPacehklnorstu',hex($_),1) } split //,'2fde0abe76c36c914586c';


Comment on Re: Generalising Forms from CGI.pm
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (7)
As of 2014-10-24 23:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (138 votes), past polls