Jump to content

array info in my contact form email not working...


jonnyroboto

Recommended Posts

I have a form that submits it's info to my email.  When people check the ckeckboxes on my form, and submit, the info comes back to me as "array".  I want to be able to see what it is they checked on so I can gather the proper info for when I call them back.  Anyone know what I'm doing wrong?

 

Form Code:

<?php


  echo ' <body bgcolor="#9999cc">

         <form action="processContact.php" method="post">


			                    
 <font face="Arial, Helvetica, sans-serif"> 
         <h1 align="center"><font size="5" color="#FFFFFF">Contact Us</font></h1>
 <div align="center"> 
   <font size="2"><strong> <font color="#FFFFFF"> Name:</font></strong> 
           <input type="text" name="name" size="30" />
           </font>
         <br />
         <br />
   <font size="2"><font color="#FFFFFF"><strong>* Email:</strong></font> 
           <input type="text" name="email" size="30" />
         </div>
         <br />
                      
         <div align="center">
           <font color="#FFFFFF">
           <strong>Overall Rating of the site:</strong><br/>
           [<input checked="checked" name="rating" type="radio" value="good" />Good] 
           [<input name="rating" type="radio" value="bad" />Fair] 
           [<input name="rating" type="radio" value="ugly" />Bad]</font> 
         <br />
 <br />
         <table>
   <tr>
     <td>
	<p align="left"><font color="#FFFFFF" size="2"><strong>* What can we help you with?</strong><br />
	<input type="checkbox" name="box[]" value="Hotel Information and Reservations" />Hotel Information and Reservations<br />
	<input type="checkbox" name="box[]" value="Vacation Home Information and Reservations" />Vacation Home Information and Reservations<br />
	<input type="checkbox" name="box[]" value="Vacation Packages and Tickets" />Vacation Packages and Tickets<br />
	<input type="checkbox" name="box[]" value="Affiliate Program Information" />Affiliate Program<br />
	<input type="checkbox" name="box[]" value="Other Information" />Other  </font>
	<font color="#FFFFFF"><input type="text" name="other" size="20" /></font></p>
     </td>
   </tr>
 </table>
         <font color="#FFFFFF">
         <br />
 <font size="1"><i>* Required Fields</i></font>
         <br />
                    	
         <h2 align="center"><font color="#FFFFFF">Comments</font></h2> 
         <div align="center">
            <font face="Arial, Helvetica, sans-serif"><textarea name="feedback" rows="6" cols="30"></textarea></font>
         </div>
  	 <hr /> ';
?>
  
<?php
    require_once('recaptchalib.php');
    $publickey = "..."; // you got this from the signup page
    echo recaptcha_get_html($publickey);
?>
  
<?php
  echo ' <br /><input type="submit" />
         </form></body> ';
?>

 

Processing Code:

<?php
require_once('recaptchalib.php');
$privatekey = "...";
$resp = recaptcha_check_answer ($privatekey,
                                $_SERVER["REMOTE_ADDR"],
                                $_POST["recaptcha_challenge_field"],
                                $_POST["recaptcha_response_field"]);

if (!$resp->is_valid) {
die ("The reCAPTCHA wasn’t entered correctly. Go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}



/* Subject and Email Variables */

$emailSubject = 'Contact Form';
$webMaster = '...';

/* Gathering Data Variables */

$emailField = $_POST['email'];
$nameField = $_POST['name'];
$ratingField = $_POST['rating'];
$box = $_POST['box'];
        $otherField = $_POST['other'];
$feedbackField = $_POST['feedback'];


$body = <<<EOD
<br><hr><br>
Email: $email <br>
Name: $name <br>
Site Rating: $rating <br>
Info Needed: $box <br>
Other Attraction Detail: $other <br>
Comments: $feedback <br>
EOD;

$headers = "From: $email\r\n";
$headers .= "Content-type: text/html\r\n";
$success = mail($webMaster, $emailSubject, $body, $headers);

/* Results Rendered HTML */

$theResults = <<<EOD
<html>

<head>
<title>Thank you!</title>

<style type="text/css">
h1 {
color: #ffffff;
text-align: center;
}

h2 {
color: #ffffff;
text-align: center;
}

h3 {
color: #ffffff;
text-align: center;
}

a:link {
color: #330033;
text-decoration: none;
}

a:visited {
color: #000033;
text-decoration: none;
}

a:hover {
color: #663399;
text-decoration: none;
}
</style>

</head>

<body bgcolor="#9999cc">

<form>
<h1>Thank you.</h1><br>
<h2>An email has been sent to us and we will be contacting you soon.</h2>
<h3>Thank you again for visiting wdwvip.com
You may click below to close this window.</h3>

<div align="center">
<input type="button" value="Close Window" onClick="window.close()"></div>
</form>
<div align="center">
<a href="javascript:window.close()">Close Window</a>
</div>
</body>

</html>
EOD;
echo "$theResults";
?>

  • 2 weeks later...

No, change the name back to "box[]".

 

Then when you did:

$box = $_POST['box'];

 

You would want to make a loop because it comes back with an array of all selected checkboxes.

 

So something like:

$boxes = $_POST['box'];
$values = '';
foreach ($boxes as $box => $value) {
     $values .= $value . ', ';
}

 

Then use $values instead of $boxes.

  • 5 weeks later...

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.