Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2010-01-13
7
Medium Priority
?
217 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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

580 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