-1

I'm trying to make a simple contact form, but I have difficulty to understand how checkbox works. This is the part I have a problem:

HTML:

<input name="selection" type="checkbox">

PHP:

$selection = $_POST['selection'];
$mail->Body = "
    Answer is ".$_POST["selection"]."
"

Once the checkbox is clicked and the form is submitted, the function above prints "Answer is on" in the e-mail. How can I print "Answer is Positive" once checkbox is clicked, and "Answer is Negative" when checkbox is not clicked in a simple way?

tez
  • 117
  • 1
  • 8

1 Answers1

0

Alright, I didn't know that defining a custom positive value for a checkbox is so simple:

HTML

<input name="selection" type="checkbox" value="Write here what you want to post when the checkbox is checked">

As for posting the negative value, I realized that it's not that necessary for my project. For those who wonder how, all alternatives are explained here:

POST unchecked HTML checkboxes

tez
  • 117
  • 1
  • 8