This switch is part of a form, I can't get this element to be posted by the PHP into email, It seems to be not picking up the checked with the data-on="Yes" data-off="No" attribute of the switch.
HTML
<form class="booking-form" name="bookchalet" action="booking_form.php" method="post">
<div id="switchbox">
<div class="switch">
<input id="cmn-toggle-1" class="cmn-toggle cmn-toggle-round" type="checkbox"/>
<label for="cmn-toggle-1"></label>
</div>
<div class="switch">
<input id="cmn-toggle-4" class="cmn-toggle cmn-toggle-round-flat" type="checkbox"/>
<label for="cmn-toggle-4"></label>
</div>
<div class="switch">
<input id="cmn-toggle-7" class="cmn-toggle cmn-toggle-yes-no" name="apartment" type="checkbox"/>
<label for="cmn-toggle-7" data-on="Yes" data-off="No" ></label>
</div>
</div>
</li>
</form>
PHP
<?php
if ($_POST["submit"]){
$apartment = $_POST['apartment'];
$submit = $_POST['submit'];
$to = 'myemail@email.com';
$headers = 'From: website' . "
";
$subject = 'FORM: '.$submit. "
";
$message = ' Booking Details: '.$submit.', With apartment?:'.$apartment.."
";
mail($to, $subject, $message, $headers); //This method sends the mail.
echo "Your email was sent!"; // success message
$url = 'index.html';
echo '<META HTTP-EQUIV=Refresh CONTENT="0; URL='.$url.'">';
}
}
?>
I have taken out other elements of the form as it was pretty long and they were posting to email correctly.
In your .php code I do not see any connection to your database and/or an insertion statement. . . Code that would look like this:
<?php
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "myDB";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "INSERT INTO MyGuests (firstname, lastname, email)
VALUES ('John', 'Doe', 'john@example.com')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>