Forum Moderators: coopster

Message Too Old, No Replies

Form Processing issue- duplicate output

when processing a complex form, I'm getting multiple output.

         

stmosaic

6:02 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



Been working on this for weeks and am quite frustrated that none of my varied modifications have made much of a difference. Is anybody able to help me out with this? I have abbreviated the code to highlight the problem areas.

When the form data is emailed, if more than one checkbox (each with a distinct name & value), is checked, the info output in the email of selections #2 and #3 are repeated 2 - 3 times. Other than that small glitch, everything works perfectly, emails go to the proper address, output in the email is formatted correctly.

Abbreviated code is below. I would appreciate any help with this!
FORM CODE SNIPPET


<input type="checkbox" name="city0" value="CryC">
<input type="checkbox" name="city1" value="CH">
<input type="checkbox" name="city2" value="OB">

ABBREVIATED PROCESSOR CODE

$CryC = $_POST['city0'];
$CH = $_POST['city1'];
$OB = $_POST['city2'];

$if ($formname == "accom" && isset($CryC))
{ $SendTo = "CryC-Accom@domain.com";
$SubjectLine = "CRYSTAL COAST $formname Lead from\n";
//variable processing//
include 'fprocessA.php';

// Send E-Mail //
if (count($_POST)!= 0)
{
$Spam = false;

foreach ($_POST as $Field=>$Value)
{
$Spam = $Spam ¦¦ stristr($Value, "bcc: ");
}

if (!$Spam)
{
$mailheaders = "From: $SendFrom \r\n";
$mailheaders .= "Reply-To: $Reply_To \r\n";
mail($SendTo, $SubjectLine, $MsgBody, $mailheaders);
}
}

}

if ($formname == "accom" && isset($CH))
{ $SendTo = "CH-Accom@domain.com";
$SubjectLine = "CHARLESTON SC $formname Lead from\n";

include 'fprocessA.php';

// Send E-Mail //
if (count($_POST)!= 0)
{
$Spam = false;

foreach ($_POST as $Field=>$Value)
{
$Spam = $Spam ¦¦ stristr($Value, "bcc: ");
}

if (!$Spam)
{
$mailheaders = "From: $SendFrom \r\n";
$mailheaders .= "Reply-To: $Reply_To \r\n";
mail($SendTo, $SubjectLine, $MsgBody, $mailheaders);
}
}

}

if ($formname == " accom" && isset($OB))
{ $SendTo = "OB-Accom@domain.com";
$SubjectLine = "NC OUTER BANKS $formname Lead from\n";

include 'fprocessA.php';

// Send E-Mail //
if (count($_POST)!= 0)
{
$Spam = false;

foreach ($_POST as $Field=>$Value)
{
$Spam = $Spam ¦¦ stristr($Value, "bcc: ");
}

if (!$Spam)
{
$mailheaders = "From: $SendFrom \r\n";
$mailheaders .= "Reply-To: $Reply_To \r\n";
mail($SendTo, $SubjectLine, $MsgBody, $mailheaders);
}
}

}

justgowithit

6:52 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



Post the a snippet from '$MsgBody' showing $CryC, $CH, $OB

stmosaic

7:04 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



$MsgBody is part of the variable processing from the include.

$MsgBody .= "Arrival Date: $Arrival_Date\n";
$MsgBody .= "Nights: $nights\n\n";

if (isset($_POST['accom_type']))
{
foreach ($_POST['accom_type'] as $accom_value) {$MsgBody .= "Requested Accommodations Type: $accom_value\n";}
}
$MsgBody .= "$Divider\n" . "Visitor IP Address:" . @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe

justgowithit

7:16 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



Hmm... If I'm following you correctly you're saying that the email is sent only once and is correct with the exception that the values of $CryC, $CH, $OB are causing a logical error within the body of the email.

There must be a loop somewhere that's misbehaving but I don't see any issues with what's up here now.

How does the value of the three variables in question affect $MsgBody.

stmosaic

7:25 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



It doesn't really, $Cry, $CH and $OB are just switches that with the formname determine where the emails are sent. That email "pathing" is working just fine. It's almost acting like it's going through the code 2 or 3 times.

What is should be doing is when it hits one of the if statements and that checkbox is checked, emails the form info to the address designated. Just one copy of the info, not multpiles in one email.

justgowithit

7:37 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



instead of
if ($formname == "accom" && isset($CH))

use

if ($formname == "accom" &&!empty($CH))

Do this for all three conditionals that look for which email to send.

stmosaic

7:47 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



Tried it, no difference. Form output continues in the same manner. 3 check boxes checked, triplicate output on the 3rd city, double output on the second city.

ABBREVIATED OUTPUT:
Address 1: TEST 4
Address 2: TEST 4
City: TEST 4
State: TEST 4

Address 1: TEST 4
Address 2: TEST 4
City: TEST 4
State: TEST 4

Address 1: TEST 4
Address 2: TEST 4
City: TEST 4
State: TEST 4

justgowithit

7:55 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



Is there another conditional or loop around these three statements?

I've got a hunch the issue is with the checkboxes, though. I would try to narrow things down by substituting the three checkboxes with textfields and then modifying the conditionals to:

if ($formname == "accom" && $CH == 'yes'))

where you'll type "yes" into each textfield you want to send.

If error still occurs the issue is elsewhere... but I bet it's not.

stmosaic

8:09 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



No joy, it continues to behave the same even when the input is coming from a text box, so it doesn't appear to be the checkboxes.

justgowithit

8:16 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



One thing I just noticed is that the first conditional has a '$' in front of the statement like $if - remove that.

Second, try dividing the conditions like:
if (($formname == "accom") && (isset($CH)))

Are you sure there's no other loops or statements that surround all three of these statements?

stmosaic

8:18 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



No other loops surrounding these ifs. The $if was a copy & paste error, sorry, it doesn't exist in my real code. I did the dividng with the text box test.

justgowithit

8:25 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



Sorry, stmosaic - I'm stumped!

stmosaic

8:26 pm on Jul 24, 2007 (gmt 0)

10+ Year Member



got to go for now. Will be back in the am. Have to get this working.

ramoneguru

1:25 am on Jul 25, 2007 (gmt 0)

10+ Year Member



Could you post the fprocessA.php code as well? I just noticed you included it twice in the code there. Also, how are you creating the test output you posted earlier?

--Nick

stmosaic

12:47 pm on Jul 25, 2007 (gmt 0)

10+ Year Member



Nick,

fprocessA assembles the email. The output comes as an email.


$MsgBody .= "Arrival Date: $Arrival_Date\n";
$MsgBody .= "Nights: $nights\n\n";
if (isset($_POST['accom_type']))
{
foreach ($_POST['accom_type'] as $accom_value) {$MsgBody .= "Requested Accommodations Type: $accom_value\n";}
}
$MsgBody .= "$Divider\n" . "Visitor IP Address:" . @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe

I'm beginning to think the problem lies in my foreach loops, since they are the only looping structures I'm using.

justgowithit

3:31 pm on Jul 25, 2007 (gmt 0)

10+ Year Member



I'm beginning to think the problem lies in my foreach loops, since they are the only looping structures I'm using.

Without a doubt - The issue just can't been seen from the code provided.

stmosaic

4:12 pm on Jul 25, 2007 (gmt 0)

10+ Year Member



Here is the reworked abbreviated code (presume all variables are defined & accounted for - they are).
PROCESSOR CODE

if ($formname == "Accommodations" && isset($CryC))
{ $SendTo = "ng-CryC-Accom@domain.com";
$SubjectLine = "NC CRYSTAL COAST $formname Lead from domain\n";
include 'fprocessA.php';
}

if ($formname == "Accommodations" && isset($CH))
{ $SendTo = "ng-CH-Accom@domain.com";
$SubjectLine = "CHARLESTON SC $formname Lead from domain\n";
include 'fprocessA.php';
}

if ($formname == "Accommodations" && isset($OB))
{ $SendTo = "ng-OB-Accom@domain.com";
$SubjectLine = "NC OUTER BANKS $formname Lead from domain\n";
include 'fprocessA.php';
}


ABBREVIATED CONTENTS OF fprocess

$MsgBody .= "Name: $name\n";
$MsgBody .= "Email: $email\n";
$MsgBody .= "Company: $Company\n";
$MsgBody .= "Address 1: $Address1\n";

$MsgBody .= "\n";
if (isset($_POST['amenities']))
{
foreach ($_POST['amenities'] as $amenity_value) {$MsgBody .= "Requested Amenities: $amenity_value\n";}
}
$MsgBody .= "$Divider\n" . "Visitor IP Address:" . @gethostbyaddr($_SERVER["REMOTE_ADDR"]) . "\n";
$MsgBody = htmlspecialchars($MsgBody); //make content safe

$mailheaders = "From: $SendFrom \r\n";
$mailheaders .= "Reply-To: $Reply_To \r\n";
mail($SendTo, $SubjectLine, $MsgBody, $mailheaders);

The only foreach loops that remain are in the formation of the email in $MsgBody. The spam filtering loops have been moved to earlier in the page. Yet, it still send duplicate info in the emails.

stmosaic

6:26 pm on Jul 25, 2007 (gmt 0)

10+ Year Member



Got it solved! It was my $MsgBody in fprocessA. 2 issues, one it was not intialized and two, the first line was concatenated when it shouldn't have been which is why the 2nd email had 2 duplications and the 3rd email had 3 duplications. Thought you'd like to know where I erred. I'd like to thank both of you for your help!

justgowithit

11:35 pm on Jul 25, 2007 (gmt 0)

10+ Year Member



Didn't really help much but I'm glad that you're on your way :)