jonsmithgraphics
asked on
how to get checkbox results to be delivered via php forrm handler
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
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" );
}
}
?>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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['requirementsBra nding'])
echo $_POST['requirementsBrandi ng'];
if($_POST['requirementsWeb site'])i
echo $_POST['requirementsWebsit e'];
as each checkbox has a name rather than a number as you showed, would that be correct?
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['requirementsBra
echo $_POST['requirementsBrandi
if($_POST['requirementsWeb
echo $_POST['requirementsWebsit
as each checkbox has a name rather than a number as you showed, would that be correct?
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
<input name="requirementsBranding
id="Branding">Company branding including; logos, stationery, packaging, signage<br /><br />
thanks, Kalpan
guys...are you still discussing the question, or am i missing something ?
ASKER
hi I am trying with both your suggestions now, watch this space....
ASKER
thanks very much to you both but ludofulop wins as it took just the one line change to get it working!
nice one : )
nice one : )
use it like this...
if($_POST['requirements1']
echo $_POST['requirements1'];
if($_POST['requirements2']
echo $_POST['requirements2'];
thanks, Kalpan
Open in new window