Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 serious problems

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Help please!!

I have two serious problems with a script I am trying to write. I am going nuts trying to figure out what's wrong.

I have written a script to take form information and parse it to be sent to an email address. The script also checks the e-mail address and phone # for validity. If the input fails the test the HTML code is regenerated with the failed input in red.

Problem #1:
When I test the script the inputted information is not being reentered into the form. Instead, if you check the source for the newly generated page you see the inputted information in the title bar. I use the HTML POST method on both scripts. Here is a sample line:

print &quot;<TR><TD WIDTH=105><B>First Name: </B></TD><TD><INPUT TYPE=\&quot;TEXT\&quot; NAME=\&quot;first\&quot; VALUE=\&quot;$first\&quot; SIZE=40 MAXSIZE=60></TD></TR>\n&quot;;


The second problem is that the e-mail checking routine always fails. Here is the routine (first I replace the ASCII values with the original @ or .):

$email = $formdata{'E-mail'};
$email =~ s/%40/@/g;
$email =~ s/%2/./g;
@check_email = split (//, $email);
foreach $letter (@check_email) {
if ($letter eq &quot;@&quot;) {
$good_email = 1;
last;
}
else {$good_email=0}
}

if (!$good_email | !$good_phone_number) {
reprint page .....}

Please help!!! I have almost gone bezerk trying to figure out whatI have done wrong here.

Thanks



 
# cgi routines
use CGI_Lite;

# parse the form elements and generate parameters
my $cgi = new CGI_Lite;
my %in = $cgi->parse_form_data;

my $phone = $in{&quot;PHONE&quot;};
my $email = $in{&quot;EMAIL&quot;};

my $good_phone = 0;
my $good_email = 0;

if ($phone =~ /\s*(\()?(\d{3})?\s*(-|\.|\))?\s*(\d{3})(\s*)(-|\.)(\s*)(\d{4})\s*/) {$good_phone = 1;}

if ($email =~ /^([\w\-_\.]+)@(([\w\-_]+)\.)+([\w]+)$/) {$good_email = 1;}

if (!($good_phone && $good_email))
{

print &quot;Content-type: text/html\n\n&quot;;

print qq~The top of your page~;

if (!$good_phone)
{
print qq~<TR><TD WIDTH=&quot;105&quot;><B><font color=&quot;#FF0000&quot;>Phone: </B></TD><TD><INPUT TYPE=&quot;TEXT&quot; style=&quot;color:#FF0000;&quot; NAME=&quot;PHONE&quot; VALUE=&quot;$phone&quot; SIZE=&quot;40&quot; MAXSIZE=&quot;60&quot;></TD></TR>\n~;
}
else
{
print qq~<TR><TD WIDTH=&quot;105&quot;><B>Phone: </B></TD><TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;PHONE&quot; VALUE=&quot;$phone&quot; SIZE=&quot;40&quot; MAXSIZE=&quot;60&quot;></TD></TR>\n~;
}

if (!$good_email)
{
print qq~<TR><TD WIDTH=&quot;105&quot;><B><font color=&quot;#FF0000&quot;>Email: </B></TD><TD><INPUT TYPE=&quot;TEXT&quot; style=&quot;color:#FF0000;&quot; NAME=&quot;EMAIL&quot; VALUE=&quot;$email&quot; SIZE=&quot;40&quot; MAXSIZE=&quot;60&quot;></TD></TR>\n~;
}
else
{
print qq~<TR><TD WIDTH=&quot;105&quot;><B>Email: </B></TD><TD><INPUT TYPE=&quot;TEXT&quot; NAME=&quot;EMAIL&quot; VALUE=&quot;$email&quot; SIZE=&quot;40&quot; MAXSIZE=&quot;60&quot;></TD></TR>\n~;
}

print qq~The rest of your page~;
}

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top