?
Solved

how to get checkbox results to be delivered via php forrm handler

Posted on 2010-01-13
7
Medium Priority
?
208 Views
Last Modified: 2012-05-08
hello,
I have a form that works fine using a php form handler. When i add in a set of checkboxes, I can't seem to get the checkbox array (requirements[])  to be delivered in the email sent by the form handler. Below is the form code and also the php form handler.

thanks for your time
<form method="post" action="sendmail2.php" onSubmit="return check_send(this);" >
<input type="hidden" name="subject" value="website enquiry">


<div id="FormCol">

<p>Please complete the form below and click on submit. 
<br />We will contact you shortly to discuss your requirements.<br /><br />

 <span>Fields marked * must be filled in.</span></p>

<label id="name">Name *</label>
<input tabindex="1" name="name" id="name" type="text" class="textField" >

<label id="company">Company *</label>
<input tabindex="2" name="company" id="company" type="text" class="textField" >

<label id="website">Website</label>
<input tabindex="3" name="website" id="website" type="text" class="textField" >

<label id="email">Your Email *</label>
<input tabindex="4" name="email" id="email" type="text" class="textField" >
     
<label id="telephone">Telephone *</label>
<input tabindex="5" name="telephone" id="telephone" type="text" class="textField" >


<label id="requirements">Your requirements (please tick)</label>

<div id="Checkboxes">



<input name="requirements[]" value="Branding" type="checkbox" tabindex="6"  
id="Branding"><p>Company branding including; logos, stationery, packaging, signage</p><br />

<input name="requirements[]" value="Website" type="checkbox"  tabindex="7" 
id="Website"><p>Website</p><br />

<input name="requirements[]" value="Planning" type="checkbox"  tabindex="8" 
id="Planning"><p>Marketing planning and execution</p><br />

<input name="requirements[]" value="PrintedMedia" type="checkbox"  tabindex="9" 
id="PrintedMedia"><p>Printed media including; sales and marketing collateral, brochures, newsletters</p><br />

<input name="requirements[]" value="ElectronicMedia" type="checkbox"  tabindex="10" 
id="ElectronicMedia"><p>Electronic media including company videos and online demo's</p><br />

<input name="requirements[]" value="SalesCampaigns" type="checkbox"  tabindex="11" 
id="SalesCampaigns"><p>Sales lead campaigns</p><br />

<input name="requirements[]" value="EventManagement" type="checkbox"  tabindex="12" 
id="EventManagement"><p>Event management</p><br />

<input name="requirements[]" value="PR" type="checkbox"  tabindex="13" 
id="PR"><p>PR campaigns</p><br />

<input name="requirements[]" value="CustomerResearch" type="checkbox"  tabindex="14" 
id="CustomerResearch"><p>Customer research</p><br />

<input name="requirements[]" value="Other" type="checkbox"  tabindex="15" 
id="Other"><p>Other</p><br />


</div>



<label id="comments">Additional Comments</label>
<textarea tabindex="16" name="comments" id="comments" rows="3" wrap="VIRTUAL"></textarea>

<br />


<input name="submit" type="image" id="sendButton" tabindex="17" value="Submit" src="Images/submit.gif" width="78" height="35">


</div>
<!--  -->
</form>



<?php
$from = 'Website'; 

$to = 'hello@email.co.uk';
 
$name        = $_POST['name'];
$company      = $_POST['company'];
$email 		= $_POST['email'];
$telephone       = $_POST['telephone'];



$requirements = $_POST['requirements'];



$comments        = $_POST['comments'];

 
if(($name=="") || ($company=="") || ($email=="") || ($telephone=="")) {
        header( "Location: error.html" );
}
else {
        $msg="name: " . $name ."\n";
         $msg.="company: " . $company ."\n";
		 $msg.="email: " . $email ."\n";
       	$msg.="telephone: " . $telephone ."\n";
		
		
	$msg.="requirements: " . $requirements ."\n";
		 
		 
		 $msg.="comments: " . $comments ."\n";

         
        if(mail("$to","Hive Marketing web enquiry",$msg,"From: $from", "-f$from")) {
           /*If sent direct customers to thankyou page */
           header( "Location: thanks.html" );
        }
        else {
           /* If there is an error display an error message */
           header( "Location: error.html" );
        }
}


?>

Open in new window

0
Comment
Question by:jonsmithgraphics
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
7 Comments
 
LVL 15

Accepted Solution

by:
ludofulop earned 2000 total points
ID: 26301869
hello, try to change this line:
$requirements = $_POST['requirements'];
to
$requirements = implode(", ", $_POST['requirements']);
0
 
LVL 14

Expert Comment

by:Kalpan
ID: 26301932
Please use the below code snippet...

use it like this...

if($_POST['requirements1'])
                echo $_POST['requirements1'];
        if($_POST['requirements2'])i
                echo $_POST['requirements2'];


thanks, Kalpan
<?php
if($_POST['submit']){
        if($_POST['requirements1'])
                echo $_POST['requirements1'];
        if($_POST['requirements2'])i
                echo $_POST['requirements2'];
        echo $_POST['name'];
}else{
?>

<form method="post" action="testcheckbox.php"  >
<input type="hidden" name="subject" value="website enquiry">


<div id="FormCol">

<p>Please complete the form below and click on submit.
<br />We will contact you shortly to discuss your requirements.<br /><br />

 <span>Fields marked * must be filled in.</span></p>

<label id="name">Name *</label>
<input tabindex="1" name="name" id="name" type="text" class="textField" >

<label id="company">Company *</label>
<input tabindex="2" name="company" id="company" type="text" class="textField" >

<label id="website">Website</label>
<input tabindex="3" name="website" id="website" type="text" class="textField" >

<label id="email">Your Email *</label>
<input tabindex="4" name="email" id="email" type="text" class="textField" >

<label id="telephone">Telephone *</label>
<input tabindex="5" name="telephone" id="telephone" type="text" class="textField" >


<label id="requirements">Your requirements (please tick)</label>

<div id="Checkboxes">

Open in new window

0
 

Author Comment

by:jonsmithgraphics
ID: 26302005
hi thanks for the quick response!

so if my checkboxes were:

<input name="requirements[]" value="Branding" type="checkbox" tabindex="6"  
id="Branding">Company branding including; logos, stationery, packaging, signage<br /><br />

<input name="requirements[]" value="Website" type="checkbox"  tabindex="7"
id="Website">Website<br /><br />

then i would have the php like this:


if($_POST['requirementsBranding'])
                echo $_POST['requirementsBranding'];
        if($_POST['requirementsWebsite'])i
                echo $_POST['requirementsWebsite'];


as each checkbox has a name rather than a number as you showed, would that be correct?
0
WordPress Tutorial 2: Terminology

An important part of learning any new piece of software is understanding the terminology it uses. Thankfully WordPress uses fairly simple names for everything that make it easy to start using the software.

 
LVL 14

Expert Comment

by:Kalpan
ID: 26302023
yes, correct...exactly....it will show the value as Branding coz you have value="Branding" in below tag...

<input name="requirementsBranding" value="Branding" type="checkbox" tabindex="6"  
id="Branding">Company branding including; logos, stationery, packaging, signage<br /><br />


thanks, Kalpan
0
 
LVL 15

Expert Comment

by:ludofulop
ID: 26302038
guys...are you still discussing the question, or am i missing something ?
0
 

Author Comment

by:jonsmithgraphics
ID: 26302073
hi I am trying with both your suggestions now, watch this space....
0
 

Author Comment

by:jonsmithgraphics
ID: 26302113
thanks very much to you both but ludofulop wins as it took just the one line change to get it working!

nice one : )
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question