homepage Welcome to WebmasterWorld Guest from 54.166.255.168
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
Forum Library, Charter, Moderators: coopster & jatar k & phranque

Perl Server Side CGI Scripting Forum

    
writing a script
Maynard49

5+ Year Member



 
Msg#: 4290 posted 4:11 am on Nov 6, 2005 (gmt 0)

Hi there im new at scripts..im trying to write a script that the user has to enter information..name phone# and zipcode..and how it shows if there is an error so the user has to correct it..if someone can help i would really appreciate it..

 

lexipixel

WebmasterWorld Senior Member 10+ Year Member



 
Msg#: 4290 posted 6:34 am on Nov 6, 2005 (gmt 0)


im trying to write a script that the user has to enter information..name phone# and zipcode..and how it shows if there is an error so the user has to correct it

The simplest way is to write the script as a simple pass or fail type loop.

Here's an outline-

1. top of script uses CGI to collect data
2. routine validates data
2a. if no data (such as first time script is run for that user) script produces a form
2b. if data exists, it is validated, ie-
- make sure "name" is more than X number of characters
- if collecting first and last name as one string, make sure there is data that matches a pattern like "abcde [space] abcdefg..."
- be sure phone number is 10 digits and can be normalized to ###-###-#### pattern
- be sure ZIP CODE is five digits
- you could go as far as you like with validating data, ie- check AREA CODE and EXCHANGE portions of phone number against a zip code database to be sure they match; make sure name, phone and zip are not typical B.S. patterns like:

Name: zzzzzzz
Phone: 555-555-5555
Zip: 99999

or other simple pattern matching to eliminate data that is being entered just to get through the form.

If data does not validate, or one or more fields is empty, produce form with user data as the value="" portion of the input.

Basically, the form will run once producing a form and the FORM ACTION will call the script again when SUBMIT button is clicked. If data does not validate it will produce form again and call the script again until it does validate.

Some other things you might incorporate:
- a hidden field with a counter that increments each time form is processsed, (after they try 4 or 5 times, you could direct them elsewhere or produce an error message.

Below is a rough start for the script, you will need to add the code to validate the data, match patterns, etc..

#!/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";
#
}

Maynard49

5+ Year Member



 
Msg#: 4290 posted 4:57 pm on Nov 6, 2005 (gmt 0)

thank you very much...im a newbie in this stuff...so i need all the help i can get...lol

thanks again for responding...i have to get this in tomm...

doug

[edited by: coopster at 8:27 pm (utc) on Nov. 6, 2005]
[edit reason] removed email per TOS [webmasterworld.com] [/edit]

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Perl Server Side CGI Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved