Jump to content

A slightly more complex post cgi

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

  • Like 1

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


  • Create New...