Jump to content

Recommended Posts

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. ;D

 

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);
?>

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?

 

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.

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.

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.