Forum Moderators: coopster

Message Too Old, No Replies

Form Validation Returns 49 Emails Instead of 1

What did I do wrong?

         

ksponline

2:12 am on Aug 5, 2003 (gmt 0)

10+ Year Member



I attempted a form validation and it seemed to work. But I did my little happy dance before I checked my inbox, which turned out to, after a long download wait, contain 98 copies of the form results in the inbox. Actually, the php file that processes the form generates 49 e-mails at a time, but I must have submitted twice initially.

So, please, can someone tell me what my error is in this code?

 

<?php

if ($ID == "")
{
$id_err = "<font color='red'>Please enter your ID Number.</font><br>";
$send = "no";
}

$Pattern = ".+@.+\..+";
if (!eregi($Pattern, $Email))
{
$email_err = "<font color=red>Your e-mail address appears to be invalid.</font><br>";
$send = "no";
}

if ($Name == "")
{
$name_err = "<font color=red>Please enter your name.</font><br>";
$send = "no";
}

if ($Bill_Address == "")
{
$billing_err = "<font color=red>Please enter your billing address.</font><br>";
$send = "no";
}

if ($City_State_Zip == "")
{
$city_err = "<font color=red>Please enter your City, State, and Zip.</font><br>";
$send = "no";
}

if ($Phone =="")
{
$phone_err = "<font color=red>Please enter your phone number.</font><br>";
$send = "no";
}

if ($send!= "no")
{

foreach($HTTP_POST_VARS as $key => $value)
{
$message .= $key . ": " . $value;
$message .= "\n";
mail("me@myaddress.net","Order Form","$message","From: $Name <$Email>");
header ("Location: thanks.php?Name=$Name");
}
}

elseif ($send == "no")
{
echo $id_err;
echo $email_err;
echo $name_err;
echo $billing_err;
echo $city_err;
echo $phone_err;
}

?>

The test form is here:
<snip>

Also, how would I validate the radio buttons with php?

Thanks for any assistance!

[edited by: jatar_k at 2:39 am (utc) on Aug. 5, 2003]
[edit reason] no urls thanks [/edit]

msr986

2:17 am on Aug 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try this:

if ($send!= "no")
{
foreach($HTTP_POST_VARS as $key => $value)
{
$message .= $key . ": " . $value;
$message .= "\n";
}
mail("me@myaddress.net","Order Form","$message","From: $Name <$Email>");
header ("Location: thanks.php?Name=$Name");
}

Birdman

2:21 am on Aug 5, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello,

If you move the mail() and header() lines outside of the foreach loop, you should be alright.

foreach($HTTP_POST_VARS as $key => $value)
{
$message .= $key . ": " . $value;
$message .= "\n";
}
mail("me@myaddress.net","Order Form","$message","From: $Name <$Email>");
header ("Location: thanks.php?Name=$Name");
}

ksponline

2:25 am on Aug 5, 2003 (gmt 0)

10+ Year Member



Thanks MSR986 and Birdman! That was it...

I understand why that happened now.

Thanks for helping so quickly too.