Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将工作复选框添加到联系人表单_Php_Html_Forms_Checkbox_Contact - Fatal编程技术网

Php 将工作复选框添加到联系人表单

Php 将工作复选框添加到联系人表单,php,html,forms,checkbox,contact,Php,Html,Forms,Checkbox,Contact,我正在尝试将复选框添加到我的联系人表单中。我有一个带有3个复选框的工作联系表。当我在这个页面()上放置我找到的php代码时,我的复选框不再可点击,但是当电子邮件发送时,所有三个复选框都会出现在电子邮件中。我想一定有一个简单的解决办法,但我已经花了整整一天的时间来解决它,这是我所能做到的 如何使复选框可单击并将所选框包含在电子邮件中 这是我的html <section class="contact"> <form id="contact" action="h

我正在尝试将复选框添加到我的联系人表单中。我有一个带有3个复选框的工作联系表。当我在这个页面()上放置我找到的php代码时,我的复选框不再可点击,但是当电子邮件发送时,所有三个复选框都会出现在电子邮件中。我想一定有一个简单的解决办法,但我已经花了整整一天的时间来解决它,这是我所能做到的

如何使复选框可单击并将所选框包含在电子邮件中

这是我的html

    <section class="contact">   
    <form id="contact" action="html_form_send.php" method="post">
    <fieldset title="About you">
    <legend><span>About you</span></legend>
    <label for="name">Name</label>
    <input type="text" name="name" id="name" tabindex="10"   class="txtinput" placeholder="Your name" required>
  <label for="email">Email</label>
  <input type="email" name="email" id="email" tabindex="20" class="txtinput" placeholder="valid email" required>
  </fieldset>
  <fieldset title="Your turn">
  <legend><span>Your turn</span></legend>
  <p>What, exactly then, are you after?</p>
  <div>
   <div class="tag">checkbox1</div>
   <input type="checkbox" id="checkbox-1" class="regular-checkbox big-checkbox" value="Yes" />
   <label for="salvation"></label>
  </div>    
  <div>
    <div class="tag">checkbox2</div>
    <input type="checkbox" id="checkbox-2" class="regular-checkbox big-checkbox" value="Yes" />
    <label for="question"></label>
  </div>    
  <div>
    <div class="tag">checkbox3</div>
    <input type="checkbox" id="checkbox-3" class="regular-checkbox big-checkbox" value="Yes" />
    <label for="other"></label>
   </div>   
   <label for="comment" class="inline"></label>
      <label for="discourse">Write your comments here</label>
     <textarea id="discourse" name="discourse" tabindex="30" class="txtinput" rows="7" placeholder="This is where your thoughts go">
     </textarea>

   <section id="buttons">
   <input type="reset" name="reset" id="resetbtn" class="resetbtn" value="Reset">
   <input type="submit" name="submit" id="submitbtn" class="submitbtn" tabindex="40" value="Send away!">
   <br style="clear:both;">
   </section>

关于你
名称
电子邮件
轮到你了
那么,你到底想要什么

复选框1 复选框2 复选框3 在这里写下你的评论
这是我的php

          <?php
if(isset($_POST['email'])) {

          // CHANGE THE TWO LINES BELOW
          $email_to = "myemail@email.org";

          $email_subject = "website feedback";


          function died($error) {
          // your error code can go here
        echo "We're sorry, but there's errors found with the form you submitted.<br /><br />";
         echo $error."<br /><br />";
         echo "Please go back and fix these errors.<br /><br />";
         die();
         }

          // validation expected data exists
         if(!isset($_POST['name']) ||
         !isset($_POST['email']) ||
         !isset($_POST['discourse'])) {
         died('We are sorry, but there appears to be a problem with the form you submitted.');      
    }

         $name = $_POST['name']; // required
         $email_from = $_POST['email']; // required
         $discourse = $_POST['discourse']; // not required  $comments =    $_POST['comments']; // required     

         $error_message = "";
         $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
         $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
          }
          $string_exp = "/^[A-Za-z .'-]+$/";
          if(!preg_match($string_exp,$name)) {
          $error_message .= 'The Name you entered does not appear to be valid.<br />';
           }
          if(strlen($discourse) < 2) {
          $error_message .= 'The Comments you entered do not appear to be valid.<br />';
          }
          if(strlen($error_message) > 0) {
    died($error_message);
           }
          $email_message = "Form details below.\n\n";

          function clean_string($string) {
          $bad = array("content-type","bcc:","to:","cc:","href");
          return str_replace($bad,"",$string);
          }

          $email_message .= "Name: ".clean_string($name)."\n";
          $email_message .= "Email: ".clean_string($email_from)."\n";
          $email_message .= "checkbox1: ".clean_string($checkbox-1)."\n";
          $email_message .= "checkbox2: ".clean_string($checkbox-2)."\n";
          $email_message .= "checkbox3: ".clean_string($checkbox-3)."\n";
          $email_message .= "Comments: ".clean_string($discourse)."\n";

          $checkbox1= $_POST['checkbox1'];
          if ($checkbox1!= 'Yes') {
          $checkbox1= 'No'; }

          $checkbox2= $_POST['checkbox2'];
         if ($checkbox2!= 'Yes') {
         $checkbox2= 'No'; }

         $checkbox3= $_POST['checkbox3'];
         if ($checkbox3!= 'Yes') {
         $checkbox3= 'No'; }

         // create email headers
         $headers = 'From: '.$email_from."\r\n".
         'Reply-To: '.$email_from."\r\n" .
         'X-Mailer: PHP/' . phpversion();
         @mail($email_to, $email_subject, $email_message, $headers);  
         ?>

          <?php
         $checkbox = $_POST['value']
          //Will return either "checkbox1" or "checkbox2" or "checkbox3".
          ?>

         <!-- place your own success html below -->

        <script language="javascript" type="text/javascript">
        alert('Thank you for contacting us.');
        window.location = 'feedbackform.html';
        </script>    
         <?php
          }

         die();
           ?>

如果复选框不可单击,则很可能有其他元素位于复选框上方。使用浏览器的开发工具是发现这一点的最快方法。PHP不影响它们是否可单击

如果我猜的话,他们的标签就在上面。(请注意,应避免使用此类空元素。)


复选框(和其他表单元素)必须具有
名称
属性才能与表单一起提交。

我一整天都在添加和删除不同的元素,但它实际上没有改变任何东西,因此可能更大的问题在于您所说的标签位于上方,而元素为空。正如您所说,我再次添加了“name”元素,但是当我试图删除div并将标签移到上面时,复选框完全消失了。或者更确切地说,我的标签好像放在不可拼的盒子上,所以我把东西放回原来的样子。如何在不丢失复选框的情况下使用标签?使用浏览器的开发人员工具来发现复选框上方是否有内容。(右键单击并检查图元或类似图元)。您也可以在标签中键入某些内容,或删除它们。如果某个元素在它们上面,那么您可以使用CSS来纠正这一点。当我将元素更改为下面的元素时,框是可选的。但是,“value”元素的内容会自动显示在框中,而框中的内容不会显示在电子邮件中,而不是用复选标记。复选框1我已经试过了,试着把上面的代码写在这里。我不明白。这行不通。