0

I have a HTML form with multiple text inputs and some checkbox inputs.

My question is, how do I post if the checkboxes are checked or not in the PHP's mail function message section?

This is my code:

HTML

<form method="post" action="">

    <label for="email"><strong>E-mail</strong></label><br />
    <input name="email" onBlur="mail(this)" type="text" value="<?php echo $email;?>"/>
    <span class="eroareMail error"><?php echo $emailErr;?></span><br />

    <label for="site"><strong>Site</strong></label><br />
    <input name="site" onBlur="numeSite(this)" type="text" value="<?php echo $site;?>"/>
    <span class="eroareSite error"><?php echo $siteErr;?></span><br />

    <h2><strong>Lorem</strong></h2>
    <p>
       Ipsum<input name="Ipsum" type="checkbox" value="<?php echo $Ipsum;?>"/> 
       Dolor<input name="Dolor" type="checkbox" value="<?php echo $Dolor;?>"/>
    </p>
</form>

PHP

$to = "sample@yahoo.com"; 
$subject = "subject";
$message = "

EMAIL: $email\r\n 
SITE: $site\r\n 
Lorem: $lorem, $ipsum\r\n 
";

mail($to,$subject,$message);
exit();

I tried this code, and some other similar ideas, but nothing works. Please help!

3 Answers3

0

You can check if the variable of your checkbox fields are checked:

<?php if(isset($_POST['Ipsum']) { echo "Ipsum is checked"; } ?>
<?php if(isset($_POST['Dolor']) { echo "Dolor is checked"; } ?>
Michael Wagner
  • 1,018
  • 8
  • 20
0
<p>
   Ipsum<input name="Ipsum" type="checkbox" value="<?php echo $Ipsum;?>"/> 
   Dolor<input name="Dolor" type="checkbox" value="<?php echo $Dolor;?>"/>
</p>

Should be changed to :

<p>
   Ipsum<input name="Ipsum" type="checkbox" value="SomeVal"/> 
   Dolor<input name="Dolor" type="checkbox" value="SomeOtherVal"/>
</p>

Otherwise you are only setting the value (for the checkbox) when the variable is already set.

Then the PHP (if you want to simply show checked or not):

$message = "
    EMAIL: $email\r\n 
    SITE: $site\r\n 
    Lorem: " . (isset($Ipsum) ? "Ipsum Yes" : "Ipsum No") . ", " . 
        (isset($Dolor) ? "Dolor Yes" : "Dolor No") . "\r\n 
";

OR (if you are looking for the value):

$message = "
    EMAIL: $email\r\n 
    SITE: $site\r\n 
    Lorem: " . $Ipsum . ", " . $Dolor . "\r\n 
";

This code makes the assumption you are registering globals (or are pushing the POST values in to variables) because you didn't ask about $email and $site.

DragonYen
  • 958
  • 9
  • 22
0

Why are you doing onBlur="mail(this)" and onBlur="numeSite(this)" before the user has even had a chance to check the check box?

Rick Savoy
  • 321
  • 4
  • 11