У меня есть простая контактная форма с флажком, после подтверждения и подтверждения я повторяю результаты формы.Я бы хотел, чтобы элемент флажка возвращал ДА, если он отмечен, и НЕТ, если пусто.
Вот мой фрагмент:
$subject = "Website Contact Form Enquiry";
//If the form is submitted
if(isset($_POST['submit'])) {
//Check to make sure that the name field is not empty
if(trim($_POST['contactname']) == '') {
$hasError = true;
} else {
$name = trim($_POST['contactname']);
}
//Check to make sure sure that a valid email address is submitted
if(trim($_POST['email']) == '') {
$hasError = true;
} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
$hasError = true;
} else {
$email = trim($_POST['email']);
}
//Check to make sure comments were entered
if(trim($_POST['message']) == '') {
$hasError = true;
} else {
if(function_exists('stripslashes')) {
$comments = stripslashes(trim($_POST['message']));
} else {
$comments = trim($_POST['message']);
}
}
if(isset($_POST['tour']) &&
$_POST['tour'] == 'yes')
{
$tour = true;
}
else
{
$tour = false;
}
//If there is no error, send the email
if(!isset($hasError)) {
$emailTo = 'info@bgv.co.za'; //Put your own email address here
$body = "Name: $name \n\nEmail: $email \n\nComments:\n $comments";
$headers = 'From: My Site <'.$emailTo.'>' . "\r\n" . 'Reply-To: ' . $email;
mail($emailTo, $subject, $body, $headers);
$emailSent = true;
}
}
Вот эхо
<?php if(isset($emailSent) && $emailSent == true) { //If email is sent ?>
<div id="sadhu">
<p class="general_site">Name:</p><p class="general_siter"><strong><?php echo $name;?></strong></p>
<p class="general_site">Email:</p><p class="general_siter"><strong><?php echo $email;?></strong></p>
<p class="general_site">Message:</p><p class="general_siter"><strong><?php echo $comments;?></strong></p>
<p class="general_site">Tour:</p><p class="general_siter"><strong><?php echo $tour;?></strong></p>
</div>
<?php } ?>