复选框提交相同的值独立的方框已选中或取消选中

时间:2018-03-25 16:51:16

标签: php

我的问题是我的电子邮件表单有一个复选框,无论是否选中该框都无关紧要,它始终传输相同的值,所有其他字段都正常工作,它只是我正在使用的复选框问题。我从这个论坛尝试了几个没有运气的建议,我不确定我做错了什么! 我不太熟悉PHP。

<form method="post" action="contact-form-handler1.php">
   <div class= "form">
     <div class="input-group margin-bottom-sm">
       <span class="input-group-addon">
         <i class="fa fa-user fa-fw" style="color:grey"></i>
     </span>
<input class="form-control" type="text" name="name" placeholder="Name" 
required>
    </div><br>
<div class="input-group margin-bottom-sm">
   <span class="input-group-addon">
      <i class="fa fa-envelope-o fa-fw" style="color:grey"></i>
    </span>
<input class="form-control" type="text" name="email" placeholder="Email 
address" required>
    </div><br>
<div class="input-group margin-bottom-sm">
   <span class="input-group-addon">
      <i class="fa fa-phone fa-fw" style="color:grey"></i>
   </span>
<input class="form-control" type="text" name="phone" placeholder="Phone">
   </div><br>
</div>
<div class="input-group margin-bottom-sm">
   <span class="input-group-addon">
     <i class="fa fa-comment-o fa-fw" style="color:grey">
   </i></span>
<textarea class="form-control" rows="6" type= "text" name="message" 
placeholder="Your Message" required></textarea>
   </div><br>
<div class="input-group margin-bottom-sm">
   <input class="form" type="hidden"  name="check" value="0">
      <input class="form" type="checkbox"  name="check" value="1"><span 
   </div>
   <br><br>
<div class="input-group margin-bottom-sm"><span class="input-group-addon">
   <i class="fa fa-lock fa-fw" style="color:grey"></i>
   </span>
<input class="form-control" type="text" name="code" placeholder="For 
security, please type SECURE in this field">
   </div><br>
<input class="btn btn-primary send" type="submit" value="Send Message">
</form>

<?php 
$errors = '';
$myemail = 'info@xyz.com';//<-----Put Your email address here.
if(empty($_POST['name'])  || 
empty($_POST['email']) ||
empty($_POST['phone']) || 
empty($_POST['message']))
{
$errors .= "\n Error: all fields are required";
}

$name = $_POST['name'];
$phone = $_POST['phone']; 
$email_address = $_POST['email']; 
$message = $_POST['message'];
$check = $_POST['check']; 

// if data is posted, set value to 1, else to 0
$check = isset($_POST['check']) ? 1 : 0;
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i", 
$email_address))
{
$errors .= "\n Error: Invalid email address";
}
if (strtolower($_POST['code']) != 'SECURE') {die('Wrong access code');
}

if( empty($errors))
{
$to = $myemail; 
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message from the
Mail Handler. ".
" Here are the details:\n Name: $name \n Phone: $phone \n Email: 
$email_address \n Message: \n $message \n Signup: $check"; 

$headers = "From: $myemail\n"; 
$headers .= "Reply-To: $email_address";

mail($to,$email_subject,$email_body,$headers);
//redirect to the 'thank you' page
header('Location: contact-form-thank-you.php');
} 

&GT;

0 个答案:

没有答案