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

Monks,

I'm trying to run a form within the results of another form script. The first script is basically a review for the user to see if the data looks correct before adding it to a MySQL db. Right now nothing is showing up in the form portion (everything below the table part) of this script and I'm not getting any errors (displayed or in the weblogs). Does anybody see why this part of my code would not be displaying?
#!/usr/bin/perl -w # Display all erors to screen $|++; # autoflush buffers; use CGI::Carp 'fatalsToBrowser'; use strict; use DBI; use CGI qw/:standard/; my $infile = upload ('file') or die "File was not uploaded correctly\n +"; my ($ip,$port,@services,@banners,@names,@ips,@ports); my %data; print header, start_html ("-title" => "Review Page"); ----------- perl stuff --------------- print "<table>"; print "<tr><br><br>"; print "<td><b><u>IPS</u> - </b>@ips<br><br>"; print "</tr>"; print "<tr>"; print "<td><b><u>Cnames</u> - </b>@names<br><br>"; print "</tr>"; print "<tr>"; print "<td><b><u>Services</u> - </b>@services<br><br>"; print "</tr>"; print "<tr>"; print "<td><b><u>Banners</u> - </b>@banners<br><br><br>"; print "</tr>"; print "</table>"; start_form( { -action => "action_dbi.cgi", -enctype => "application/x-www-form-urlencoded", -method => "post" } ), h1( strong( "Does this format look correct?" ) ), checkbox_group(-name=>'question', -values=>['yes','no'], -default=>['yes'], p( "&nbsp;" ), p( input( { -type => "submit", -value => "submit"} ), ), #end p end_form, end_html;


Thanks,
Dru
Another satisfied monk.

Replies are listed 'Best First'.
Re: CGI form Not Showing Up.
by broquaint (Abbot) on May 01, 2002 at 16:05 UTC
    You need to print() the return of start_form as it just returns a string of the form tag that it's built up e.g
    print start_form( { -action => "action_dbi.cgi", -enctype => "application/x-www-form-urlencoded", -method => "post" } ); __output__ <form method="post" action="action_dbi.cgi" enctype="application/x-www +-form-urlencoded">

    HTH

    _________
    broquaint

      Once you add a "print" in front of your start_form(), see if your form displays...

      If not, I'm having the same problem. See my note on "Perl CGI..."

      Note that I'm not using CGI.pm in my script, so it's pure Perl/print's...

      - Mush
Re: CGI form Not Showing Up.
by thunders (Priest) on May 01, 2002 at 16:36 UTC
    one matter of style, i prefer the qq(); function over so many print statements, it prints prettier because it recognizes new lines instead of forcing you to put in \n over and over(right now you're printing all your html on one line, which is hard to debug.
    print qq( <table> <tr><br><br> <td><b><u>IPS</u> - </b>@ips<br><br> </tr> <tr> <td><b><u>Cnames</u> - </b>@names<br><br> </tr> <tr> <td><b><u>Services</u> - </b>@services<br><br> </tr> <tr> <td><b><u>Banners</u> - </b>@banners<br><br><br> </tr> </table> ), start_form( { -action => "action_dbi.cgi", -enctype => "application/x-www-form-urlencoded", -method => "post" } ), h1( strong( "Does this format look correct?" ) ), checkbox_group(-name=>'question', -values=>['yes','no'], -default=>['yes'], p( "&nbsp;" ), p( input( { -type => "submit", -value => "submit"} ), ), #end p end_form, end_html;
Re: CGI form Not Showing Up. (Style Comment)
by talexb (Chancellor) on May 01, 2002 at 17:22 UTC
    Another question of style -- why not use CGI.pm's routines for all of your table items as well?
    print table( Tr( br, br, td( b( u( "IPS" ) " - " ) ), @ips, br, br ), Tr( br, br, td( b( u( "CNames" ) " - " ) ), @names, br, br ), Tr( br, br, td( b( u( "Services" ) " - " ) ), @services, br, br ), Tr( br, br, td( b( u( "Banners" ) " - " ) ), @banners, br, br ) );
    (Note: I haven't tested this code!)

    You could do something even cooler by having the titles and arrays stuffed into an array. Later, adding a new row to your report would just mean adding a line to the array -- without code changes! (That's the Lazy part of Laziness, Impatience and Hubris in Perl.)

    --t. alex

    "Nyahhh (munch, munch) What's up, Doc?" --Bugs Bunny

      (Note: I haven't tested this code!)
      You only want td() or th() elements directly inside of Tr() elements, otherwise the content will print out somewhere strange. this is closer:
      #!/usr/bin/perl use CGI qw/:standard/; sub nl{ return qq(\n) } @ips = ("1.2.3.4","2.4.6.8","3.6.9.12"); @names = ("A1","B2","C3"); @services = ("srv1","srv2","srv3"); @banners = ("ban1.1","ban2.2","ban3.3"); print table( Tr([ td(br.br.b(u("IPS")." - @ips".br.br)).nl, td(br.br.b(u("Names")." - @names".br.br)).nl, td(br.br.b(u("Services")." - @services".br.br)).nl, td(br.br.b(u("Banners")." - @banners".br.br)).nl, ]).nl, ).nl;
        Good one, although I note that you're using concatenation rather than the more efficient list separator ('.' as opposed to ','). And what's the nl for?

        --t. alex

        "Nyahhh (munch, munch) What's up, Doc?" --Bugs Bunny

Re: CGI form Not Showing Up.
by Cyrnus (Monk) on May 01, 2002 at 23:17 UTC
    All good tips above. I'd like to add one more note about a personal style preference that makes it easier for me to keep track of form elements.
    #build form elements my $openform = start_form( { -action => "action_dbi.cgi", -enctype => "application/x-www-form-urlen +coded", -method => "post" } ); my $chk_question = checkbox_group(-name=>'question', -values=>['yes','no'], -default=>['yes']); my $cmd_submit = input( { -type => "submit", -value => "submit"} ); #print form print <<End_of_Form; $openform h1( strong( "Does this format look correct?" ) ) $chk_question p( "&nbsp;" ) p( $cmd_submit) end_form() End_of_Form
    This code would replace the code for the form you posted. Basicly I'm putting the results of the functions that generate the form elements into variables and interpolating them into a here document. It makes the here document easier to read and it groups your form elements together to make then easier to edit/update. John