|
|
Subject:
For validation with perl script
Category: Computers > Programming Asked by: stevepr-ga List Price: $10.00 |
Posted:
05 Jun 2004 12:12 PDT
Expires: 05 Jul 2004 12:12 PDT Question ID: 356823 |
I am trying to get a form validated with a perl script. I know very litle about perl. It has to be done in perl because its a school project. I am running windows xp with active perl and IIS. Here is teh Html Form that needs validated. <html> <body> <form name="MyForm" method="post" action="/scripts/11-01.pl"> <p>Name: <input type="text" name="name" /> </p> <p>Address: <input type="text" name="address" /> </p> <p>Zip code: <input type="text" name="zip" /> </p> <p>Social Security: <input type="text" name="social" /> </p> <p>DOB: <input type="text" name="dob" /> </p> <p>Mothers Maiden Name: <input type="text" name="maiden" /> </p> <p> </p> <p> <input type="submit" /> </p> </form> </body> </html> ***END**************************************** I am not shure if this html form is good or if the submit buton needs some help? Here is the perl scrip so far: #!c:/perl/bin print "Content-type: text/html\n\n"; read(STDIN,$tempbuffer,$ENV{?CONTENT LENGTH'}); @pairs=split(/&/,$tempbuffer); foreach $item(@pairs) { $error = ""; if ($in{'dd'} eq "") { $error += "Please Enter a value.<p>"; } } ***END**************************************** I will be honest I have been copying and pasting from here and there for this script but finally called it quits. |
|
Subject:
Re: For validation with perl script
Answered By: palitoy-ga on 05 Jun 2004 13:12 PDT Rated: |
Hello Stevepr You are very nearly there! Here is the script that you require: #==================================================== #!c:/perl/bin print "Content-type: text/html\n\n"; $data_length = $ENV{'CONTENT_LENGTH'}; $bytes_read = read(STDIN, $my_data, $data_length); @name_value_array = split(/&/, $my_data); foreach $name_value_pair (@name_value_array) { ($name, $value) = split(/=/, $name_value_pair); $name =~ tr/+/ /; $value =~ tr/+/ /; $name =~ s/%(..)/pack("C",hex($1))/eg; $value =~ s/%(..)/pack("C",hex($1))/eg; if (length($value) == 0) { print "Please Enter a value.<p>"; } else { print $name . ": " . $value . "<P>"; }; } #==================================================== You may wish to alter the code slightly depending on whether you wish to process the name part of the name:value pair passed by the HTML page. The code for the HTML page is perfect (as long as the location of the .pl script is correct). You may also wish to alter what is printed out at the end of the script. If you need any more help please ask for clarification and I will do my best to help you out. | |
| |
| |
| |
| |
| |
|
stevepr-ga rated this answer: |
|
Subject:
Re: For validation with perl script
From: jesseuml-ga on 15 Jul 2004 05:24 PDT |
I have a problem related to this discussion that perhaps you can shed some light on. As a preamble, please note that I am aware of the Perl CGI.pm module, but I am trying to demonstrate very basic CGI concepts and therefore have written the following code without using CGI.pm capabilities. Here is a snippet of code that is part of a form processing script intended to handle both GET and POST methods: # extract form data regardless of submission method my $formData ; print "<p>Request method: <code><b>", $ENV{ "REQUEST_METHOD" }, "</b></code></p>" ; if ( $ENV{ "REQUEST_METHOD" } eq "GET" ) { $formData = $ENV{ "QUERY_STRING" } ; } else { read STDIN, $formData, $ENV{ "CONTENT_LENGTH" } ; } print "<p>Form data: <code><b>$formData</b></code></p>" ; This code works perfectly with the Apache server and Perl 5.8.4 on both Windows 2000 and Linux systems. With the IIS server on Windows XP Professional, it works fine for GET methods, but with POST the read statement simply hangs. If I comment the read statement out, the script runs fine, although of course I don't see the data passed from the form. I know that POST works with IIS on Windows XP because I can do something similar using the facilities in CGI.pm. I simply can't understand why the read statement is hanging in the above code. My code seems to be analogous to similar code that I have found in numerous books, Web sites, and newsgroup postings. Do you happen to have any idea or any suggestions of what to try? Thanks for any suggestions you can offer. Jesse |
If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you. |
Search Google Answers for |
Google Home - Answers FAQ - Terms of Service - Privacy Policy |