Checkbox in emailForm.php
3 posts by 2 authors in: Forums > CMS Builder
Last Post: July 16, 2013 (RSS)
By Toledoh - July 15, 2013
Hi Guys,
I'm using the standard emailForm.php, but trying to add checkboxes using the following:
<input type = "checkbox" name = "director" value = "1" <?php checkedIf(1, @$_REQUEST['director']);?> />Directors’ guideline:<br />
<input type = "checkbox" name = "trustee" value = "1" <?php checkedIf(1, @$_REQUEST['trustee']);?> />Trustees’ guideline: <br />
<input type = "checkbox" name = "business" value = "1" <?php checkedIf(1, @$_REQUEST['business']);?> />Business owners’ guideline<br />
<input type = "checkbox" name = "all" value = "1" <?php checkedIf(1, @$_REQUEST['all']);?> />All guideline
then, when sending the email I use:
Director: {$_REQUEST['director']}
Trustee: {$_REQUEST['trustee']}
Business: {$_REQUEST['business']}
All: {$_REQUEST['all']}
which works if the check box is ticked, but returns an error if the check box is left unticked.. "Undefined index: director....."
Any thoughts?
Tim (toledoh.com.au)
By gregThomas - July 16, 2013
Hi Tim,
The issue is that when a browser submits a form if a checkbox is not ticked it doesn't send a value at all as opposed to sending an empty or negative value. I would check if values have been sent, and then create some variables to add to your e-mail. Something like this should work:
Creating the variables
<?php
$director = (@$_REQUEST['director'])? 'Yes' : 'No' ;
$trustee = (@$_REQUEST['trustee'])? 'Yes' : 'No' ;
$business = (@$_REQUEST['business'])? 'Yes' : 'No' ;
$all = (@$_REQUEST['all'])? 'Yes' : 'No' ;
?>
Add the strings to your e-mail
Director: {$director}
Trustee: {$trustee}
Business: {$business}
All: {$all}
Let me know if you have any questions.
Cheers
Greg
PHP Programmer - interactivetools.com