Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
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';

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://236500]
help
Chatterbox?
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (4)
As of 2016-12-04 04:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    On a regular basis, I'm most likely to spy upon:













    Results (61 votes). Check out past polls.