maynard49 has asked for the wisdom of the Perl Monks concerning the following question:

hi there im trying to create a name address and zipcode script and all i get is errors..yes im a newbie..trying to understand this..can someone help with a simple script please..it would be most appreciated...

you can also email me at maynard48@comcast.net

thanks

doug

#!/usr/local/bin/perl # $script_URL = "url of script goes here"; # use CGI; $query = new CGI; $name = ($query->param("f_name")); $tel = ($query->param("f_tel")); $zip = ($query->param("f_zip")); # if ($name$tel$zip eq '') { # &showform; # } else { # print "Name: $name<BR>\n"; print "Tel: $tel<BR>\n"; print "Zip: $zip<BR>\n"; } exit; ############## sub showform { ############## # print "<FORM ACTION=$script_URL METHOD=POST>\n"; print "<B>Name:</B> <INPUT TYPE=text NAME=f_name SIZE=24 value=\"$name +\"><BR>\n"; print "<B>Tel:</B> <INPUT TYPE=text NAME=f_tel SIZE=12 value=\"$tel\"> +<BR>\n"; print "<B>Zip:</B> <INPUT TYPE=text NAME=f_zip SIZE=5 value=\"$zip\">< +BR>\n"; print "<INPUT TYPE=submit VALUE=\"SUBMIT\">\n"; # }

2005-11-06 jdporter Inserted the content from Reaped: form script, which is very close to the original version of this node.

Replies are listed 'Best First'.
Re: help with a form
by jdporter (Paladin) on Nov 06, 2005 at 17:42 UTC

    Smells like homework...

    We're building the house of the future together.
Re: help with a form
by jZed (Prior) on Nov 06, 2005 at 19:08 UTC
    I would suggest using strict and warnings and setting values to empty string to avoid warnings. Try something like this:
    #!/usr/local/bin/perl use warnings; use strict; use CGI; my $script_URL = "url of script goes here"; my $query = new CGI; print $query->header(); my $name = $query->param("f_name") || ''; my $tel = $query->param("f_tel") || ''; my $zip = $query->param("f_zip") || ''; if ( "$name$tel$zip" eq '' ) { &showform; } else { print "Name: $name\n"; print "Tel: $tel\n"; print "Zip: $zip\n"; } sub showform { print "<FORM ACTION=$script_URL METHOD=POST>\n"; print "Name: <INPUT TYPE=text NAME=f_name SIZE=24 value=\"$name\"> +\n"; print "Tel: <INPUT TYPE=text NAME=f_tel SIZE=12 value=\"$tel\">\n" +; print "Zip: <INPUT TYPE=text NAME=f_zip SIZE=5 value=\"$zip\">\n"; print "<INPUT TYPE=submit VALUE=\"SUBMIT\">\n"; }
    update: added missing content-header
Re: help with a form
by graff (Chancellor) on Nov 07, 2005 at 01:25 UTC
    all i get is errors...

    And you can learn something from those error messages. If you don't understand them, show us what the messages are, and when they refer to line numbers in your code, make it clear in the code that you post which lines those are (e.g. add something like  # this is line XX at the end of the XX'th line).

    For example, one of the errors would have cited this line:

    if ($name$tel$zip eq '') { # you want $name.$tel.$zip or "$name$tel$ +zip"
    If you include "use strict;" at the top, you might get more error messages -- and this is good, because these would identify problems that might be hard to spot otherwise (e.g. spelling errors in variable names -- you don't seem to have any now, but they can happen at any time).