473,698 Members | 2,134 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Having a problem processing a form with Perl

numberwhun
3,509 Recognized Expert Moderator Specialist
Hello everyone! I am dabbling in processing forms using Perl and having only just begun, I am already having problems. Go figure. :-)

Top begin with, here it the form's html, its nothing at all complicated:

Expand|Select|Wrap|Line Numbers
  1. <div id="formcontent">
  2.     <h3>The New Information Gathering Form</h3>
  3.     <form action="./cgi-bin/process_form.cgi" method="post">
  4.         <fieldset>
  5.             <legend><strong>Personal Information</strong></legend>
  6.             <label for="firstname">First Name:</label>
  7.             <input type="text" id="firstname" maxlength="25"/><br />
  8.             <label for="lastname">Last Name:</label>
  9.             <input type="text" id="lastname" maxlength="30"/><br />
  10.             <label>Date Of Birth:</label>
  11.             <label for="dobmonth" class="date">Month</label>
  12.             <input type="text" maxlength="2" id="dobmonth" size="2" />
  13.             <label for="dobday" class="date">Day</label>
  14.             <input type="text" maxlength="2" id="dobday" size="2" />
  15.             <label for="dobyear" class="date">Year</label>
  16.             <input type="text" maxlength="4" id="dobyear" size="4" /><br/>
  17.             <label>Gender:</label>
  18.             <input type="radio" name="gender" value="Male" /> <label for="gender" class="sex">Male</label>
  19.                 <input type="radio" name="gender" value="Female" /> <label for="gender" class="sex">Female</label><br />
  20.  
  21.         </fieldset>
  22.         <br />
  23.         <fieldset>
  24.             <legend><strong>Contact Information</strong></legend>
  25.             <label for="address1">Address1:</label>
  26.             <input type="text" id="address1" /><br />
  27.             <label for="address1">Address2:</label>
  28.             <input type="text" id="address2" /><br />
  29.             <label for="city">City:</label>
  30.             <input type="text" id="city" /><br />
  31.             <label for="state">State:</label>
  32.             <input type="text" id="state" /><br />
  33.             <label for="zipcode">Zip Code:</label>
  34.             <input type="text" id="zipcode" /><br />
  35.             <label for="phone">Phone #:</label>
  36.             <input type="text" id="phone" alt="In the format XXX-XXX-XXXX" /><label class="format">(XXX-XXX-XXXX)</label><br />
  37.         </fieldset>
  38.         <br />
  39.         <fieldset>
  40.                <legend><strong>Form Control</strong></legend>
  41.                <input type="submit" value="Submit" class="submit" />
  42.                <input type="reset" value="Reset Form" />
  43.         </fieldset>
  44.     </form>
  45. </div>
  46.  
Please know that with the css I have, it will look a lot prettier. If you want to see the form in all its glory, please see this link

If you put in information and hit submit, you will see that it errors. No, there isn't a 500 page as of yet, but that's not the issue. If I execute the script by hand, I get the following error:

[code]
[Mon Aug 18 10:41:57 2008] process_form.cg i: Use of uninitialized value in read at ./process_form.cg i line 22.
[code]


The following is the script that I have put together to process the above form after submission.


Expand|Select|Wrap|Line Numbers
  1. #!/usr/local/bin/perl
  2.  
  3. # The following line needed as the host puts a perl
  4. # directory in your site home directory that contains
  5. # ALL the Perl modules that are installed on the site. 
  6. # Its basically everything.
  7. use lib '/home/jkwebdev/perl';
  8.  
  9. ##### use statements #####
  10. use strict;
  11. use warnings;
  12. use CGI::Carp qw(fatalsToBrowser);
  13.  
  14. ##### Variable Declarations #####
  15. my @pairs;
  16. my $pair;
  17. my $value;
  18. my $name;
  19. my %form;
  20. my $buffer;
  21.  
  22. ##### 
  23. if ($ENV{'REQUEST_METHOD'} eq 'POST') {
  24.  
  25.     read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
  26.  
  27.     @pairs = split(/&/, $buffer);
  28.  
  29.     foreach $pair (@pairs) {
  30.         ($name, $value) = split(/=/, $pair);
  31.         $value =~ tr/+/ /;
  32.         $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
  33.         $form{$name} = $value;
  34.     }
  35.  
  36. }
  37.  
  38. for my $key ( keys %form ) {
  39.     my $value = $form{$key};
  40.     print "$key => $value\n";
  41. }
  42.  
All I want to do at first is print out all of the values so I can get a visual on it and that isn't even working.

Any help will be greatly appreciated!

Best regards,

Jeff
Aug 18 '08 #1
8 1619
KevinADC
4,059 Recognized Expert Specialist
Why aren't you using the CGI module to get the form data Jeff?

Expand|Select|Wrap|Line Numbers
  1. use lib qw(.....);
  2. use strict;
  3. use warnings;
  4. use CGI::Carp qw/fatalsToBrowser/;
  5. use CGI;
  6. my $q =  CGI->new;
  7. my $form = $q->Vars;
  8. print $q->header(),
  9.        $q->start_html();
  10. foreach my $keys (keys %form) {
  11.     print "$keys = $form{$keys}<br/>\n";
  12. print $q->end_html;
  13. exit;
Aug 18 '08 #2
KevinADC
4,059 Recognized Expert Specialist
Is that your website Jeff?
Aug 18 '08 #3
numberwhun
3,509 Recognized Expert Moderator Specialist
Why aren't you using the CGI module to get the form data Jeff?
To tell you the truth, I am pretty much just starting to play with CGI and was going off of a tutorial.

I think that I will go and read through the CGI module and use your example. Thanks!

Jeff
Aug 18 '08 #4
numberwhun
3,509 Recognized Expert Moderator Specialist
Is that your website Jeff?
Why yes, yes it is, but don't take it at face value. Its been around a little while and is severely lacking in the update department. That will change though as I am starting to play with things like Drupal and want to revamp the entire thing. (plus maybe even finish it.) :-)

Regards,

Jeff
Aug 18 '08 #5
KevinADC
4,059 Recognized Expert Specialist
To tell you the truth, I am pretty much just starting to play with CGI and was going off of a tutorial.

I think that I will go and read through the CGI module and use your example. Thanks!

Jeff
You are reading the old tutorial, that site has an updated tutorial using the CGI module. While it is good to know some of the behind the scenes workings of CGI form processing, do not use that code in a live script.
Aug 18 '08 #6
numberwhun
3,509 Recognized Expert Moderator Specialist
You are reading the old tutorial, that site has an updated tutorial using the CGI module. While it is good to know some of the behind the scenes workings of CGI form processing, do not use that code in a live script.
Lovely! You would think that they would take down the old one or at least mark it deprecated or something. Sheesh!! Thanks for the 411, I appreciate it and will check out their other tutorial.

FYI, that link came from a Google. search.

Regards,

Jeff

**update: Ok, I dug out my copy of hooked on phonics and learned that the stuff at the top of the web page in question actually says what you were saying. :-) I think I need sleep!!!
Aug 18 '08 #7
KevinADC
4,059 Recognized Expert Specialist
Why yes, yes it is, but don't take it at face value. Its been around a little while and is severely lacking in the update department. That will change though as I am starting to play with things like Drupal and want to revamp the entire thing. (plus maybe even finish it.) :-)

Regards,

Jeff
hehehe.... don't worry, we've all been there and done that.
Aug 18 '08 #8
eWish
971 Recognized Expert Contributor
hehehe.... don't worry, we've all been there and done that.
At least he used the code tags when posting his code :)
Aug 19 '08 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

1
2650
by: Andrew | last post by:
I have written some code in Java to do some simple image processing on the server. Esentially, the program takes a jpeg image and scales it to a given size. I need to know what would be involed to convert this code to Perl since I know very little about Perl.
5
1610
by: stephenburgess1972 | last post by:
Would C++ be a good choice for programming server-side applications for form processing? Or is there a better choice out there? Thanks.
6
2957
by: Mark | last post by:
I'm building a web utility to do some processing that will run for several hours. Assume I have a valid reason for using the web for the utility. During the process I'd like to display an update on the job's status while not stopping the process that is running. It does not need to be pretty. I'd be quite happy with a quick Response.Write("Job has finished consuming 300 of 9356 bananas"); or similar. I don't care if the message is...
4
4863
by: js | last post by:
Just my curiosity. Can python beats perl at speed of grep-like processing? $ wget http://www.gutenberg.org/files/7999/7999-h.zip $ unzip 7999-h.zip $ cd 7999-h $ cat *.htm bigfile $ du -h bigfile du -h bigfile
2
1154
by: traravind | last post by:
Hi all, I am a newbie to perl programming and am already loving it.. I have a problem with my code in research and am trying to improve the performance by parallel processing some blocks of code. I have a perl module where I consecutively process data even though there are not dependent on each other. For example, my $i= 4; . .
0
2659
by: Ofelia | last post by:
Hi, I'm new to this forum and to Perl language but I would like to ask for your help. I'm working in Linux and the files I need to process are in the format “file.gz”. I created a script which should decompress, open and then delete nearly 400 files. To do so I use "open FILEPT, "zcat $filename|"". In the beginning the script works fine, but after about 300 files processed I get an error on Open function: “proc: Could not open file...
2
3572
by: rustyc | last post by:
Well, here's my first post in this forum (other than saying 'HI' over in the hi forum ;-) As I said over there: ... for a little side project at home, I'm writing a ham radio web site in uby/Rails. I started it in Perl and gave up on Perl as I went from the 'display the database information on the web page' to the 're-display the information from the database and allow the user to update the database using the web page' stage and realized...
5
2052
by: patelxxx | last post by:
I have a FORM with allows user to input their name and then user clicks submit which this goes to my .cgi script. Can someone check this .cgi script as the results are not being displayed as expected. My post_it.cgi: #!C:/perl/bin/perl.exe print "Content-type:text/html\n\n"; @values = split(/&/,$ENV{'QUERY_STRING'}); foreach $i(@values) {
3
1722
by: karthikchittur | last post by:
Hello scripters Requirement: I am trying to write a perl script that manipulate a html file. Both the html file and the script are placed at central server. I have scheduled one more script in client PC to run at start-up, that calls this server script with required arguments and the HTML page is updated accordingly. This is not server client architecture but a static server script called from client PC The problem: The scripts I have...
0
8674
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9157
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9023
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8861
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6518
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5860
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4615
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3045
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
1999
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.