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

I have a simple online form, however when I fill it in using "get" it returns an empty QUERY_STRING. When I use the "post" method, it gives me CONTENT_LENGTH=0. I cannot figure out what I am doing wrong.

Here is the xml code

<?xml version="1.0" encoding="utf-8" ?> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>Make a booking</title> <script src="makeBooking.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="makeBooking.css" +/> </head> <body> <form id="frmBook" action="/cgi-bin/makeBooking.pl" method="PO +ST"> <table id="tblBook" > <tbody id="tblBookBody"> <tr id="nameRow"> <td class="left">Name</td> <td class="right"> <input id="txtName" type="text" /> </td> </tr> <tr id="dateRow"> <td class="left">Date</td> <td class="right"> <input id="txtDate" type="text" /> </td> </tr> <tr id="durationRow"> <td>Duration</td> <td class="right"> <input id="txtDuration" type="text" /> </td> </tr> <tr id="venueRow"> <td>Venue</td> <td class="right"> <input id="txtVenue" type="text" /> </td> </tr> <tr id="otherInfoRow"> <td>Other Information</td> <td class="right"> <textarea id="otherInfoTxt" rows="5"></textare +a> </td> </tr> <tr> <td class="left"> <div><input type="submit" value="Submit" /></d +iv> </td> <td class="right"> <div> <input type="reset" value="Reset" /> </div></td> </tr> </tbody> </table> </form> </body> </html>
and here is the perl script:
#!/usr/bin/perl print "Content-type: text/html\n\n"; print "Query string=$ENV{'QUERY_STRING'}";

Simple code, I know, but I can proceed to better things once that simple test works

The output I get is

Query string=

I am not sure where the problem lies, however, I am confident the wise monks know and I look forward to your assistance.

Irvy

Replies are listed 'Best First'.
Re: %ENV is returning a blank
by Anonymous Monk on Aug 18, 2011 at 21:54 UTC

    Your form is sending POST data and you're trying to decode GET data... they're not the same thing. I highly suggest you spend some time learning CGI and I also recommend using the fine CGI module to help you do it right.

      Sorry, I posted the above in a hurry before I went to work, I therefore got the post and get methods mixed. I have tried both, post and get, and both give me empty data back.

        Sorry, I posted the above in a hurry before I went to work, I therefore got the post and get methods mixed. I have tried both, post and get, and both give me empty data back.

        Instead of your program, try something like this instead

        #!/usr/bin/perl -- use strict; use warnings; use CGI; use Data::Dumper; #zum debuggen Main( @ARGV ); exit( 0 ); sub Main { my $cgi = CGI->new; print $cgi->header(); # Write HTTP header print $cgi->start_html, $cgi->b(rand time, ' ', scalar gmtime), '<table border="1" width="%100"><tr><td>', $cgi->Dump, '</td><td><div style="white-space: pre-wrap; overflow: scroll;">', $cgi->escapeHTML( Dumper( $cgi ) ), '</div></td></tr></table>', CGI->new( \%ENV )->Dump, $cgi->end_html; }

        Reading the manual is fundamental
Re: %ENV is returning a blank
by Anonymous Monk on Aug 18, 2011 at 20:53 UTC

    I am not sure where the problem lies...

    Find out how QUERY_STRING works and you'll have your answer