jeffman

A slightly more complex post cgi

2 posts in this topic

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

1 person likes this

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now