Jump to content

A slightly more complex post cgi


jeffman

Recommended Posts

In the next chilling installment of this series, we see a perl script that prints a form when it receives no arguments. When it receives some post data, if barfs it back. The real difference between this script and the former is that it works with form data sent in the POST mode. (CGI.pm does not distinguish between GET and POST arguments, though you could extract the difference if you wanted to.)

#!/usr/bin/perl  use CGI;    $query = new CGI;    $content = <<END_CONTENT;    <form id="FormName" action="your.domain/post.cgi" method="post" name="FormName">	 <label>First Name</label>	 <input type="text" name="firstName" />	 <br />	 <label>Last Name</label>	 <input type="text" name="lastName" />	 <br />	 <input type="submit" name="sendButton" value="Send" />  </form>    END_CONTENT    if (@NAMES = $query->param){	 $content = "";	 for $name (@NAMES) {		if ($name ne "sendButton"){		   $value = $query->param($name);		   $content .= "$name = $value<br>";		}	 }  }    print $query->header();    print <<END_HTML;    <html>	 <head>		<title>Parsing parameters</title>	 </head>	 <body>		$content	 </body>  </html>    END_HTML      #end post.cgi

Link to comment
Share on other sites

Remember: perl scripts do not usually copy and paste very well. The usual villain is newline/carriage return characters. If you do want to paste this one, if you get an error, you might try deleting all the end-of-lines and then simply hitting your return key to reinsert the proper end-of line code. Or, you could just retype the thing.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...