DannyDD Posted May 23, 2007 Share Posted May 23, 2007 Hi, I'm hacking together a form/php combination which emails the completed form. The only issue I'm having are with checkboxes.. form.html <table width="342" border="0"> <tr> <td width="99">Name</td> <td width="227"><input name="name" type="text" id="name" value="" size="25" /></td> </tr> <tr> <td>Address</td> <td><input name="address" type="text" id="address" value="" size="25" /></td> </tr> <tr> <td>Phone number</td> <td><input name="phone" type="text" id="phone" value="" size="25" /></td> </tr> <tr> <td>email address</td> <td><input name="email" type="text" id="email" value="" size="25" /></td> </tr> </table> <table width="611" border="1"> <tr> <td width="234">Geothermal heat pumps <input type="checkbox" name="geo" id="geo" /></td> <td width="177">Air to water heat pumps <input type="checkbox" name="airtowater" id="airtowater" /></td> <td width="178">Wood pellet <input type="checkbox" name="wood" id="wood" /></td> </tr> <tr> <td>Rainwater harvesting <input type="checkbox" name="rain" id="rain" /></td> <td>Potable water <input type="checkbox" name="potable" id="potable" /></td> <td>Solar <input type="checkbox" name="solar" id="solar" /></td> </tr> <tr> <td>Heat recovery ventilation systems <input type="checkbox" name="heat" id="heat" /></td> <td> </td> <td> </td> </tr> </table> ... submit... When the user completes form.html it gets sent to form.php for processing. I can email all the variables passed from the form except for the checkboxes. How do I check to see if the checkboxes have been ticked and then include this in my email?Thanks in advance. form.php echo "We will be in contact with you shortly.<br>"; $to = "asdasd@asdasd.com"; $subject = "form submitted."; $message = <<<EOF $_POST[name] submitted an domestic heating design service form. Name: $_POST[name] Address: $_POST[address] Phone: $_POST[phone] Email: $_POST[email] EOF; mail ($to, $subject, $message); ?> Quote Link to comment https://forums.phpfreaks.com/topic/52672-solved-form-php-trouble-getting-checkbox-results/ Share on other sites More sharing options...
chigley Posted May 23, 2007 Share Posted May 23, 2007 Not 100% sure how their values are set. Test it by putting this in your form.php: <?php echo "<pre>".print_r($_POST,true)."</pre>"; And comparing the values of the checkboxes. Quote Link to comment https://forums.phpfreaks.com/topic/52672-solved-form-php-trouble-getting-checkbox-results/#findComment-260015 Share on other sites More sharing options...
DannyDD Posted May 23, 2007 Author Share Posted May 23, 2007 Not 100% sure how their values are set. Test it by putting this in your form.php: <?php echo "<pre>".print_r($_POST,true)."</pre>"; And comparing the values of the checkboxes. Thanks for the reply. The checkbox boolean values are passed when the user clicks the submit form. So what I need to do is setup variables for the $_POST variables as follows: $geo = $_POST['geo']; $rain = $_POST['rain']; $heat = $_POST['heat']; $airtowater = $_POST['airtowater']; $potable = $_POST['potable']; $wood = $_POST['wood']; $solar = $_POST['solar']; I guess I then need to see if each variable is true or false and include these answers in the email. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/52672-solved-form-php-trouble-getting-checkbox-results/#findComment-260019 Share on other sites More sharing options...
chigley Posted May 23, 2007 Share Posted May 23, 2007 Yes so add the line I said above and submit the form with test values to see what the returns of checkboxes are. Quote Link to comment https://forums.phpfreaks.com/topic/52672-solved-form-php-trouble-getting-checkbox-results/#findComment-260022 Share on other sites More sharing options...
paul2463 Posted May 23, 2007 Share Posted May 23, 2007 yes if you put what chigley asked you to at the top of your form.php and run the form.html as a test checking a couple of the check boxes etc. what the print_r() function will do is to tell you exactly what is past in the $_POST array. so check geo and rain then submit it and see what the array says on the form.php. Quote Link to comment https://forums.phpfreaks.com/topic/52672-solved-form-php-trouble-getting-checkbox-results/#findComment-260024 Share on other sites More sharing options...
DannyDD Posted May 23, 2007 Author Share Posted May 23, 2007 Thanks for the replies. I think it is solved. form.php $geo = $_POST['geo']; echo "We will be in contact with you shortly.<br>"; $to = "asd@asd.com"; $subject = "form submitted."; $message = <<<EOF Name: $_POST[name] Address: $_POST[address] Phone: $_POST[phone] Email: $_POST[email] geo tickbox: $geo EOF; mail ($to, $subject, $message); The above passes emails the value of $geo which is either true or false. If it is true ON is printed, if false nothing is printed.Thanks a lot for your prompt assistance. Quote Link to comment https://forums.phpfreaks.com/topic/52672-solved-form-php-trouble-getting-checkbox-results/#findComment-260037 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.