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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with email form script

Status
Not open for further replies.

MarcLodge

Programmer
Feb 26, 2002
1,886
GB
Hi All,
I have a site hosted by a company that supplies an amendable script to accept data from a form and email it. This script works fine, except I have a check box with multiple values, and only one value is coming thru to the email. I have no idea what language the script is in, even though I've been able to configure it for my purposes. I'm guessing I need to loop round the check box value, but have no idea how to do this in the unknown language! Can anybody help? The script is as follows, the multiple check box is the last variable, names 'Camps':

<?PHP $fmt_Response=implode(&quot;&quot;, file(&quot;response.htt&quot;));
$fmt_Mail=implode(&quot;&quot;, file(&quot;Mail.htt&quot;));

while(list($Key, $Val)= each($HTTP_POST_VARS)) {
$fmt_Response=str_replace(&quot;{$Key}&quot;, $Val, $fmt_Response);
$fmt_Mail=str_replace(&quot;{$Key}&quot;, $Val, $fmt_Mail);
}

$name = $HTTP_POST_VARS[&quot;name&quot;];
$address = $HTTP_POST_VARS[&quot;address&quot;];
$phone = $HTTP_POST_VARS[&quot;phone&quot;];
$email = $HTTP_POST_VARS[&quot;email&quot;];
$age = $HTTP_POST_VARS[&quot;age&quot;];
$sex = $HTTP_POST_VARS[&quot;sex&quot;];
$Experience = $HTTP_POST_VARS[&quot;Experience&quot;];
$TShirtSize = $HTTP_POST_VARS[&quot;TShirtSize&quot;];
$Comments = $HTTP_POST_VARS[&quot;Comments&quot;];
$Camps = $HTTP_POST_VARS[&quot;Camps&quot;];

$mailText = &quot;$fmt_Mail \n\t Name: $name \n\t Address: $address \n\t Phone Number: $phone \n\t E-Mail: $email \n\t Sex: $sex \n\t Experience: $Experience \n\t T-ShirtSize: $TShirtSize \n\t Comments: $Comments \n\t Interested in Camps: $Camps &quot;;

mail($HTTP_POST_VARS[&quot;recipient&quot;], $HTTP_POST_VARS[&quot;subject&quot;], $mailText );
echo $fmt_Response;
?>
 
Do your check boxes all have the same name? DeZiner
Never be afraid to try something new.
Remember that amateurs built the Ark.
Professionals built the Titanic
 
Yes, they all have the same name, there's about 5 different ones coded as:
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;Camps&quot; VALUE=&quot;Whistler&quot;>
(but obviously all with a different Value)
 
Hi Wullie, Sorry it's taken a little while to reply but I've been away on vacation. Code is as follows....

<HTML>
<HEAD>
<TITLE>CRC Sculling Camps - Registration Page</TITLE>
<LINK REL=&quot;stylesheet&quot; HREF=&quot;crcstyles.css&quot; TYPE=&quot;text/css&quot;> <SCRIPT LANGUAGE=&quot;JavaScript&quot; TYPE=&quot;text/javascript&quot;>
<!-- Begin
function validform(regform)
{
if (regform.name.value == &quot;&quot;)
{ alert(&quot;Please enter your name&quot;)
regform.name.focus()
return false
}
if (regform.address.value == &quot;&quot;)
{ alert(&quot;Please enter your address&quot;)
regform.address.focus()
return false
}
if (regform.email.value == &quot;&quot;)
{ alert(&quot;Please enter your e-mail address&quot;)
regform.email.focus()
return false
}

Campswitch = 0
for (i=0; i<regform.Camps.length;i++)
{ if (regform.Camps.checked)
{ Campswitch = 1
}
}
if (Campswitch == 0)
{ alert(&quot;Please select one or more Camps and dates that you are interested in&quot;)
return false
}
return true
}

// End -->
</SCRIPT>
</HEAD>
<BODY>
<!-- The line below is the line that have to be added to ALL pages that goes in the main frame -->
<SCRIPT LANGUAGE=&quot;JavaScript1.2&quot; SRC=&quot;cframe.js&quot; TYPE=&quot;text/javascript&quot;></SCRIPT>
<H1 ALIGN=&quot;center&quot;>Registration and Information request</H1>
<P>Please fill out the following form and click the Submit button to send.
We will then contact you with more information The fields marked
<FONT COLOR=&quot;#FF0000&quot;>*</FONT> are required.</P>
<FORM ONSUBMIT=&quot;return validform(this)&quot; METHOD=&quot;post&quot; action=&quot;formmail.php3&quot;>
<input type=&quot;hidden&quot; name=&quot;recipient&quot; value=&quot;emailaddr@hotmail.com&quot;>
<input type=&quot;hidden&quot; name=&quot;subject&quot; value=&quot;Information Request&quot;>
<TABLE BORDER=&quot;0&quot; CELLPADDING=&quot;5&quot; WIDTH=&quot;100%&quot;>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;right&quot;> <B>Name:</B><FONT
COLOR=&quot;#FF0000&quot;>*</FONT> </TD>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot;>
<INPUT TYPE=&quot;text&quot; NAME=&quot;name&quot; SIZE=&quot;30&quot;> </TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;right&quot;> <B>Address:</B><FONT
COLOR=&quot;#FF0000&quot;>*</FONT> </TD>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot;> <TEXTAREA NAME=&quot;address&quot; ROWS=&quot;6&quot; COLS=&quot;60&quot;></TEXTAREA></TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;right&quot;> <B>Tel #:</B> </TD>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot;>
<INPUT TYPE=&quot;text&quot; NAME=&quot;phone&quot; SIZE=&quot;25&quot;> </TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;right&quot;> <B>E-Mail:</B><FONT
COLOR=&quot;#FF0000&quot;>*</FONT> </TD>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot;>
<INPUT TYPE=&quot;text&quot; NAME=&quot;email&quot; SIZE=&quot;50&quot;> </TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;Right&quot;> <B>Age:</B> </TD>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot;> <INPUT TYPE=&quot;text&quot; NAME=&quot;age&quot;
SIZE=&quot;3&quot;> </TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;Right&quot;> <B>Sex:</B></TD>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot;>
<INPUT TYPE=&quot;radio&quot; NAME=&quot;sex&quot; VALUE=&quot;Male&quot;>Male
<INPUT TYPE=&quot;radio&quot; NAME=&quot;sex&quot; VALUE=&quot;female&quot;>Female </TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;Right&quot;> <B>Experience Level:</B></TD>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot;>
<INPUT TYPE=&quot;radio&quot; NAME=&quot;Experience&quot; VALUE=&quot;Beginner&quot;>Beginner
<INPUT TYPE=&quot;radio&quot; NAME=&quot;Experience&quot; VALUE=&quot;Intermediate&quot;>Intermediate
<INPUT TYPE=&quot;radio&quot; NAME=&quot;Experience&quot; VALUE=&quot;Advanced&quot;>Advanced </TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;Right&quot;> <B>T-Shirt Size:</B></TD>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot;>
<INPUT TYPE=&quot;radio&quot; NAME=&quot;TShirtSize&quot; VALUE=&quot;S&quot;>S
<INPUT TYPE=&quot;radio&quot; NAME=&quot;TShirtSize&quot; VALUE=&quot;M&quot;>M
<INPUT TYPE=&quot;radio&quot; NAME=&quot;TShirtSize&quot; VALUE=&quot;L&quot;>L
<INPUT TYPE=&quot;radio&quot; NAME=&quot;TShirtSize&quot; VALUE=&quot;XL&quot;>XL </TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;right&quot;> <B>Please tell us how you heard about the
camps, or make any othe comments</B> </TD>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot;> <TEXTAREA NAME=&quot;Comments&quot; ROWS=&quot;6&quot; COLS=&quot;60&quot;></TEXTAREA></TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot; COLSPAN=&quot;2&quot;> <B> Please indicate which
camp(s) you are requesting information for:</B><FONT
COLOR=&quot;#FF0000&quot;>*</FONT></TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot; COLSPAN=&quot;2&quot;>
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;Camps&quot; VALUE=&quot;Henley&quot;> <B> Henley-on-Thames,
England: Sunday September 29 - Saturday October 5, 2002</B></TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot; COLSPAN=&quot;2&quot;>
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;Camps&quot; VALUE=&quot;Seville Week1&quot;> <B> Seville, Spain:
</B> Week One, <B> Sunday November 24 - Saturday November 30, 2002</B></TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot; COLSPAN=&quot;2&quot;>
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;Camps&quot; VALUE=&quot;Seville Week2&quot;> <B> Seville, Spain:
</B> Week Two, <B> Sunday December 1 - Saturday December 7, 2002</B></TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot; COLSPAN=&quot;2&quot;>
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;Camps&quot; VALUE=&quot;Elberton Week1&quot;> <B> Elberton,
Georgia: </B> Week One, <B> Sunday February 23 - Saturday March 1,
2003</B></TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot; COLSPAN=&quot;2&quot;>
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;Camps&quot; VALUE=&quot;Elberton Week2&quot;> <B> Elberton,
Georgia: </B> Week Two, <B> Sunday March 2 - Saturday March 8, 2003</B></TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot; COLSPAN=&quot;2&quot;>
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;Camps&quot; VALUE=&quot;Whistler&quot;> <B> Whistler BC, Canada:
April 2003</B></TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;left&quot; COLSPAN=&quot;2&quot;>
<INPUT TYPE=&quot;checkbox&quot; NAME=&quot;Camps&quot; VALUE=&quot;Penrith&quot;> <B> Penrith, Australia:
October 2003</B></TD>
</TR>
<TR VALIGN=&quot;TOP&quot;>
<TD VALIGN=&quot;TOP&quot; ALIGN=&quot;center&quot; COLSPAN=&quot;2&quot;>
<BUTTON TYPE=&quot;submit&quot; NAME=&quot;&quot;>
<IMG SRC=&quot;images/crcoar.gif&quot; WIDTH=&quot;70&quot; HEIGHT=&quot;22&quot; BORDER=&quot;0&quot;
ALT=&quot;Register&quot;><B> Click here to Submit </B></BUTTON>
<!-- <INPUT TYPE=&quot;IMAGE&quot; NAME=&quot;Image1&quot; VALUE=&quot;submit&quot; SRC=&quot;images/crcoar.gif&quot;> submit-->
</TD>
</TR>
</TABLE> </FORM> </BODY>
</HTML>
 
Hi mate,

Sorry, I did notice you had posted but I have been really busy with the launch of my new site.

I really cannot see the problem here..

Have you tried changing the order of the fields to see if that makes a difference?

Put the checkboxes as the first item in the form and try that. If the checkboxes work and the end of the form is missing, then the script is the problem.

BTW.. You might also want to post this in the PHP forum for them to check the script.

forum434

Hope this helps Wullie

 
Hi mate,

Try the following instead of the script that you have:

Code:
<?PHP     $fmt_Response=implode(&quot;&quot;, file(&quot;response.htt&quot;));
         $fmt_Mail=implode(&quot;&quot;, file(&quot;Mail.htt&quot;));

         while(list($Key, $Val)= each($HTTP_POST_VARS)) {
               $fmt_Response=str_replace(&quot;{$Key}&quot;, $Val, $fmt_Response);
               $fmt_Mail=str_replace(&quot;{$Key}&quot;, $Val, $fmt_Mail);
         }

    $name = $HTTP_POST_VARS[&quot;name&quot;];
    $address = $HTTP_POST_VARS[&quot;address&quot;];
    $phone = $HTTP_POST_VARS[&quot;phone&quot;];
    $email = $HTTP_POST_VARS[&quot;email&quot;];
    $age = $HTTP_POST_VARS[&quot;age&quot;];
    $sex = $HTTP_POST_VARS[&quot;sex&quot;];
    $Experience = $HTTP_POST_VARS[&quot;Experience&quot;];
    $TShirtSize = $HTTP_POST_VARS[&quot;TShirtSize&quot;];
    $Comments = $HTTP_POST_VARS[&quot;Comments&quot;];
 for each($HTTP_POST_VARS[&quot;Camps&quot;] as $Camp){$allCamps .= $Camp.&quot;\n&quot;; }

    $mailText = &quot;$fmt_Mail \n\t Name: $name \n\t Address: $address \n\t Phone Number: $phone \n\t E-Mail: $email \n\t Sex: $sex \n\t Experience: $Experience \n\t T-ShirtSize: $TShirtSize \n\t Comments: $Comments \n\t Interested in Camps: $Camp &quot;;

         mail($HTTP_POST_VARS[&quot;recipient&quot;], $HTTP_POST_VARS[&quot;subject&quot;], $mailText );
         echo $fmt_Response;
   ?>

Hope this helps Wullie

 
Wullie,
Gave it a go, and it doesn't seem to work. I get:

Warning: Variable passed to each() is not an array or object

on the

while(list($Key, $Val)= each($http_POST_VARS)) {

line, and:

Parse error: parse error, expecting `'(''

on the

for each($http_POST_VARS[&quot;Camps&quot;] as $Camp){$allCamps .= $Camp.&quot;\n&quot;; }

line

Thanks every so much for taking the time and effort to help.
Marc
 
Wullie,
I've had a fiddle and managed to get rid of the 1st error by changing the lower case http to upper case throughout the script.
Can't get rid of the other one tho, no matter how hard I try (remember I've not got the faintest clue what I'm doing!).
I'm going to try your previous suggestion in the old script of changing the order, just to see if that makes any difference
Marc
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top