Click to See Complete Forum and Search --> : Form - results
camp9483
01-10-2006, 05:57 PM
Hello again.
My form is working awesomely - with all of your help might I add - so, Thank You.
The last hurdle that I am trying to overcome is this:
I have a spot on the form where the user can select various checkboxes. However, when I receive an email (containing the results of the form) I only get one of the boxes that were checked. For Example, on my page I have this:
"How did you hear about us?"
* Design Survey
* Referral
* Other
The user can select any and all of those, but when I get the email, it'll only say "Design Survey".
I'm most familiar with the interface of dreamweaver and this is what the form looks like Picture1.pdf (attached). The attributes if you click on the first check box, for instance, look like picture2.pdf (also attached).
Can anyone offer any help which would allow me to get all o fthe results of the form?
I'll be trying random things to see if I can get it to work.
Thanks in advance,
Dale
jlknauff
01-10-2006, 08:13 PM
Post your code, I'll show you where it's wrong.
camp9483
01-10-2006, 08:43 PM
Here's the code - thanks for the help
<form action="FeedbackForm.php" method="post" name="Feedback" id="Feedback">
<p class="PageHeaders">Feel free to take a couple seconds and let us know what you think of our site, say hello or ask us a question. Well get back to you as soon as we can. </p>
<table width="100%" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="center" valign="middle">
<div align="center"></div>
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="0">
<tr>
<td align="right" valign="top"><div align="right">Full name: </div></td>
<td><input name="FullName" type="text" id="FullName" /></td>
</tr>
<tr>
<td align="right" valign="top"><div align="right">Company name: </div></td>
<td><input name="CompanyName" type="text" id="CompanyName" /></td>
</tr>
<tr>
<td align="right" valign="top"><div align="right">Phone:</div></td>
<td><input name="Phone" type="text" id="Phone" /></td>
</tr>
<tr>
<td align="right" valign="top"><div align="right">Email:</div></td>
<td><input name="Email" type="text" id="Email" onchange="MM_validateForm('Email','','NisEmail');return document.MM_returnValue" /></td>
</tr>
<tr>
<td align="right" valign="top"><div align="right">How did you hear about Spark Plug? </div></td>
<td align="left" valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td><input name="HowDidYouHear" type="checkbox" id="HowDidYouHear" value="RandomSearch" /></td>
<td>Random Search </td>
</tr>
<tr>
<td><input name="HowDidYouHear" type="checkbox" id="HowDidYouHear" value="Referral" /></td>
<td>Referral</td>
</tr>
<tr>
<td><input name="HowDidYouHear" type="checkbox" id="HowDidYouHear" value="DesignDirectory" /></td>
<td>Design Directory </td>
</tr>
<tr>
<td><input name="HowDidYouHear" type="checkbox" id="HowDidYouHear" value="Other" /></td>
<td>Other (Please specify below) </td>
</tr>
</table></td>
</tr>
<tr>
<td align="right" valign="top"><div align="right">Additional comments or information: </div></td>
<td><textarea name="Comments" cols="25" rows="15" id="Comments"></textarea></td>
</tr>
<tr>
<td> </td>
<td> </td>
</tr>
</table></td>
</tr>
<tr>
<td height="40"><div align="center">
<input type="submit" name="Submit" value="Submit" />
</div></td>
</tr>
</table>
<div align="center">
</form>
ecsyle
01-10-2006, 09:39 PM
If you change 'name="HowDidYouHear"' to 'name="HowDidYouHear[]"' you will end up with an array you can process. All the selected elements will be in that array. Then in your php code loop through the array to get the values.
foreach($_POST['HowDidYouHear'] as $how){
print $how
}
jlknauff
01-10-2006, 09:55 PM
Take a look at the form here: (http://www.wildfiremarketinggroup.com/contact.php) and change as needed.
No need to use an array.
ecsyle
01-10-2006, 10:33 PM
That form doesn't use checkboxes, it uses radio buttons. You can only have one radio button per group selected whereas checkboxes allow you to make multiple selections.
He will need to use an array.
camp9483
01-11-2006, 01:46 PM
Thanks for the feedback guys -
ecsyle,
Forgive me for being so naive, but when it comes to code, I'm still a little apprehensive as to where things get placed. Where exactly in my code do I need to put the revised php code?? The last thing I want to do is guess and create more of a mess.
Thanks again,
Dale
here's my current php code:
<?PHP
# ----------------------------------------------------
# -----
# ----- Forms To Go v2.6.11 by Bebosoft, Inc.
# -----
# ----- http://www.bebosoft.com/
# -----
# ----------------------------------------------------
# -----
# ----- UNREGISTERED COPY
# -----
# ----- Forms To Go is shareware
# ----- Please register the software
# -----
# ----------------------------------------------------
error_reporting(7);
#----------
# Validate: String
function check_string($value, $low, $high, $mode, $optional)
{
if ( (strlen($value) == 0) && ($optional === true) ) {
return true;
} elseif ( (strlen($value) >= $low) && ($mode == 1) ) {
return true;
} elseif ( (strlen($value) <= $high) && ($mode == 2) ) {
return true;
} elseif ( (strlen($value) >= $low) && (strlen($value) <= $high) && ($mode == 3) ) {
return true;
} else {
return false;
}
}
#----------
# Validate: Email
function check_email($email, $optional)
{
if ( (strlen($email) == 0) && ($optional === true) ) {
return true;
} elseif ( eregi("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,4})$", $email) ) {
return true;
} else {
return false;
}
}
if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ClientIP = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
$ClientIP = $_SERVER['REMOTE_ADDR'];
}
# RegisterGlobals OFF
$FTGFullName = $_POST['FullName'];
$FTGCompanyName = $_POST['CompanyName'];
$FTGPhone = $_POST['Phone'];
$FTGEmail = $_POST['Email'];
$FTGHowDidYouHear = $_POST['HowDidYouHear'];
$FTGComments = $_POST['Comments'];
$FTGSubmit = $_POST['Submit'];
if (get_magic_quotes_gpc) {
$FTGFullName = stripslashes($FTGFullName);
$FTGCompanyName = stripslashes($FTGCompanyName);
$FTGPhone = stripslashes($FTGPhone);
$FTGEmail = stripslashes($FTGEmail);
$FTGHowDidYouHear = stripslashes($FTGHowDidYouHear);
$FTGComments = stripslashes($FTGComments);
$FTGSubmit = stripslashes($FTGSubmit);
}
# Fields Validations
$validationFailed = false;
if ( (! check_string($FTGFullName, 3, 36, 3, false))) {
$validationFailed = true;
}
if ( (! check_string($FTGCompanyName, 3, 36, 3, false))) {
$validationFailed = true;
}
if ( (! check_email($FTGEmail, false))) {
$validationFailed = true;
}
# Redirect user to the error page
if ($validationFailed == true) {
header("Location: http://www.sparkplugcreative.com/contact/error.htm");
exit;
}
# Email to Form Owner
$emailTo = '"webmaster" <info@sparkplugcreative.com>';
$emailSubject = "Feedback From Website";
$emailSubject = preg_replace('/[\x00-\x1F]/', '', $emailSubject);
$emailFrom = "$FTGEmail";
$emailFrom = preg_replace('/[\x00-\x1F]/', '', $emailFrom);
$emailBody = "FullName: $FTGFullName\n"
. "CompanyName: $FTGCompanyName\n"
. "Phone: $FTGPhone\n"
. "Email: $FTGEmail\n"
. "HowDidYouHear: $FTGHowDidYouHear\n"
. "Comments: $FTGComments\n"
. "\n"
. "";
$emailHeader = "From: $emailFrom\n"
. "Reply-To: $emailFrom\n"
. "MIME-Version: 1.0\n"
. "Content-type: text/plain; charset=\"ISO-8859-1\"\n"
. "Content-transfer-encoding: quoted-printable\n";
mail($emailTo, $emailSubject, $emailBody, $emailHeader);
# Redirect user to success page
header("Location: http://www.sparkplugcreative.com/contact/success.htm");
exit;
# End of PHP script
?>
ecsyle
01-11-2006, 06:46 PM
I would add this chunk at line 76:
/* HANDLE CHECKBOXES */
if(is_array($FTGHowDidYouHear)){
foreach($FTGHowDidYouHear as $v){
$FTGHow .= "$v, ";
}
}
This checks to make sure $FTGHowDidYouHear is an array, then it loops through the array, creating a new string of all the selected choices.
Then at line 122, change
. "HowDidYouHear: $FTGHowDidYouHear \n"
to read
. "HowDidYouHear: $FTGHow\n"
camp9483
01-11-2006, 06:50 PM
Awesome.
Will do - hopefully this will work for me...
Do I need to list things that will be in the array or will it see that there are choices?
I'll be back soon to check...
camp9483
01-11-2006, 06:59 PM
I did as you said and I'm still getting "array" as a result when the email submission comes in....
this is mad!
ecsyle
01-11-2006, 07:20 PM
Try commenting out this (line 72): $FTGHowDidYouHear = stripslashes($FTGHowDidYouHear);
If you want to remove slashes from the elements in the array we can just add it to the loop from earlier. I tested this in my server with your form and its working fine.
camp9483
01-11-2006, 07:50 PM
commenting out?
I'm pretty unfamiliar with what that means...
the thing that I'm confused about is the fact that I never specified (other than naming all of the checkboxes the same name) what was in the array..
But by commenting out, do you mean get rid of/delete?
camp9483
01-11-2006, 08:00 PM
I deleted line 72 and it works!
the only freaky thing is that my "comments" don't appear in the email submissin - if it's isn't one thing, it's the other!?!?!!
ecsyle
01-11-2006, 08:20 PM
Cool. Odd that the comments aren't coming through though.
PHP Commenting:
http://www.phpbuilder.com/manual/language.basic-syntax.comments.php
camp9483
01-12-2006, 02:21 AM
Yeah - I cannot get the "additional comments" results to display. I'll keep trying to figure out what's going on.
Any help or advice is appreciated!
Thanks.