Jump to content

Html/PHP contact form checkboxes array


calverdesigns

Recommended Posts

Hi guys,

 

I'm quite new to php - I've made forms before but not come across having to make checkbox options appear in email.

 

I've searched the forum and have found similar posts but none of the answers have worked for me as I think it's the way I've written my code.

 

 

What happens currently is when the form is emailed the "help" option just says Array. What I want it to do is give me multiple answers if the user has clicked more than one checkbox. - I think i'm close but just missing the php code and now I'm going round in circles.

 

here is my html for the section I need to get working (checkboxes):

 

 
     
         <input type="checkbox" name="help" id="acting" value="Acting">Acting<br>
<input type="checkbox" name="help[]" id="singing" value="Singing">Singing 
<br />
<input type="checkbox" name="help[]" id="dancing" value="Dancing">Dancing
<br />
 
<input type="checkbox" name="help[]" id="general_advice" value="General Advice">General Advice 
 
 
           
 
 
 
 
 
 
And here is my PHP (in full)
 
 
 
 
<?php
if(isset($_POST['email'])) {
 
// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "[email protected]";
$email_subject = "New";
 
 
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form your submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
 
// validation expected data exists
if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['telephone']) ||
!isset($_POST['location']) ||
!isset($_POST['help']) ||
!isset($_POST['considering']) ||
!isset($_POST['comments']))
{
died('We are sorry, but there appears to be a problem with the form your submitted.');
}
 
$name = $_POST['name']; // required
$email_from = $_POST['email']; // required
$telephone = $_POST['telephone']; // required
$location = $_POST['location']; // required
$comments = $_POST['comments']; // required
$help = $_POST['help']; // required
$considering = $_POST['considering']; // required
 
 
$error_message = "";
$email_exp = "^[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$";
  if(!eregi($email_exp,$email_from)) {
  $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
$string_exp = "^[a-z .'-]+$";
  if(!eregi($string_exp,$name)) {
  $error_message .= 'The Name you entered does not appear to be valid.<br />';
  }
  if(strlen($comments) < 2) {
  $error_message .= 'The Comments you entered do not appear to be valid.<br />';
  }
  if(strlen($error_message) > 0) {
  died($error_message);
  }
$email_message = "
----------------------------------
FORM DETAILS BELOW
----------------------------------
\n\n";
 
function clean_string($string) {
 $bad = array("content-type","bcc:","to:","cc:","href");
 return str_replace($bad,"",$string);
}
 
$email_message .= "Name: ".clean_string($name)."
\n";
 
 
$email_message .= "Email: ".clean_string($email_from)."
\n";
 
$email_message .= "Telephone: ".clean_string($telephone)."
\n";
 
$email_message .= "Location: ".clean_string($location)."
\n";
 
$email_message .= "I need help with: ".clean_string($help)."
\n";
 
$email_message .= "I am considering: ".clean_string($considering)."
 
\n";
 
 
 
$email_message .= "Comments:
 
".clean_string($comments)."\n";
 
 
 
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  ;}
?>
 

 

Any help would be greatly appreciated. 

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/280759-htmlphp-contact-form-checkboxes-array/
Share on other sites

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.