Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

Pre-Populate HTML form

by peacemaker1820 (Pilgrim)
on Jan 22, 2003 at 17:43 UTC ( #229090=perlquestion: print w/replies, xml ) Need Help??

peacemaker1820 has asked for the wisdom of the Perl Monks concerning the following question:

I would like to populate my form with some predefined values in perl file. I am trying to use HTML::FillInForm, but the page returns a blank page to me. I DO have the HTML page that I am trying to populate, and for testing purposes I put it into the same directory where my perl file is.
Can anyone help with any ideas that would make this thing work? Because if it will, I will have to pre-populate a form that I have with about 40 fields.
Thanks a lot brothers. Here is the code so far...

print "HTTP/1.0 200 OK\n"; print "Content-Type: text/html\n\n"; use warnings; use CGI; use HTML::FillInForm; my $q = new CGI; my $fif = new HTML::FillInForm; #name of the form to populate #(in the same directory for testing purposes) my $html = "name1.htm"; #Fill in the necessary parameters... $q->param("name" , "Ted Burns"); my $output = $fif->fill(scalarref => \$html, fobject=>$q); #print the form with values in the fields print $output; ####### END

Replies are listed 'Best First'.
Re: Pre-Populate HTML form
by bart (Canon) on Jan 22, 2003 at 17:50 UTC
    $fif->fill(scalarref => \$html, ...)
    expects $html to contain the raw HTML, i.e. the contents of the file. Alternatively, use
    $fif->fill(file => $htmlfile, ...)
    where $htmlfile contains the name/path of the file.

    You appear to have mixed the two forms, and it doesn't seem to work well.

      Thanks...that's exactly what I was looking for!

      One more question though...the above will pre-populate the form with values in the form boxes, but can I also pre-populate a <SPAN ID="sp1"></SPAN> tag? Meaning I would also like to achieve the same effect as with form fields--pre-populating the SPAN tags with some "TEXT" by reffering to its ID. I really need this.

      Thanks a lot.
Re: Pre-Populate HTML form
by linebacker (Scribe) on Jan 22, 2003 at 20:12 UTC
    Seems like you also might just use the with default values. Psuedo-code (basically just Lincoln Stein CGI documentation ) follows:
    #!/usr/local/bin/perl use CGI qw(:standard); print header; print start_html('Lincoln Stein Rocks the Perlmonk Example'), h1('Perlmonk Example'), start_form, "What's the combination?",p, checkbox_group(-name=>'words', -values=>'eenie','meenie','minie','moe'],
    p, "What's your favorite color? ", popup_menu(-name=>'color', -values=>'red','green','blue','chartreuse']), p, submit, end_form, hr; print end_html;
      Mixing HTML, even in its CGI-function-conceiled form, with code in this way is almost never a good idea, though. I've found that even in cases of small scripts where I started out like this, I'd've been better served to opt for a template(ish) solution right off the bat. On the other hand, ever since I got into the habit of doing that, I've never found myself wishing I hadn't put forth the effort to separate out the HTML. The reason is scalability - templates are easier to grow complexity into as you go, which is important CGI scripts tend not to be one-off, throw-away solutions. Rather, even in simple ones tend to hang around for significant periods of time, and I've found that nearly every single one of them eventually grew. If not by much, then still enough so to make matters of initial organization important down the road.

      Makeshifts last the longest.

Re: Pre-Populate HTML form
by OM_Zen (Scribe) on Jan 22, 2003 at 20:22 UTC
    Hi ,

    the cgi 's method multipart_start $cgi->multipart_start(-type=>'text/plain'), multipart_end
    shalll do that , is that what you were thinking to do in your code, a multipart form with cgi methods or some thing like that , you have more in perldoc CGI in your machien unix or windows where perl is installed you can see that for sure or some doc somewhere

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://229090]
Approved by broquaint
Front-paged by newrisedesigns
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2020-11-27 10:21 GMT
Find Nodes?
    Voting Booth?

    No recent polls found