I have a form with 4 checkboxes. When the boxes are checked, the email generated from the form displays the default 'on', for each checkbox that is checked.
I wanted to change this to 'Yes'. The problem is that although I can change the default to 'Yes' using the code below, 'Yes' now appears next to every option in the email, whether the checkboxes were checked on the form or not. I am new to PHP and so far none of the answers I've searched address the problem I'm having. Any suggestions on how to fix would be much appreciated. Thanks!
The HTML
<input type="checkbox" name="red" id="red" value="yes">
<label for="red">Red</label></p><p>
<input type="checkbox" name="blue" id="blue" value="yes">
<label for="blue">Blue</label></p><p>
<input type="checkbox" name="green" id="green" value="yes">
<label for="green">Green</label></p><p>
<input type="checkbox" name="yellow" id="yellow" value="yes">
<label for="yellow">Yellow</label>
The PHP
$red = $_POST['red'];
if ($red != 'Yes') {
$red = 'Yes';
}
$blue = $_POST['blue'];
if ($blue != 'Yes') {
$blue = 'Yes';
}
$green = $_POST['green'];
if ($green != 'Yes') {
$green = 'Yes';
}
$yellow = $_POST['yellow'];
if ($yellow != 'Yes') {
$yellow = 'Yes';
}
Thanks!
Aucun commentaire:
Enregistrer un commentaire