Html php联系表单重定向

时间:2017-11-30 11:10:43

标签: php html wordpress contact-form

所以我一直在打破这个问题,如果我说错了,我很新意。所以我得到了主机,安装了wordpress,然后我把它放在它上面,它用html编写的conctact形式,它有单独的php文件和进程。它有点工作,如果我测试它,它会发给我一封电子邮件,但我把标题('Location:../ front-page.php');我得到错误行的白页,我很确定没有错误,如果你去网站,它使用该行,它工作得很好,问题只是在提交表格后。我正在添加一个代码并将PHP放入Javascript中。如果可能的话还有一些额外的相关问题,是否有可能在重定向到首页的同时添加成功消息的警报表?现在,当我收到消息时,我看不到那个写电子邮件的人,而且它非常重要,也很好修复。非常感谢你们!

<?php 

// define variables and set to empty values
$name_error = $email_error = $message_error = "";
$name = $email = $phone = $message = $url = $success = "";

//form is submitted with POST method
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  if (empty($_POST["name"])) {
    $name_error = "Name is required";
  } else {
    $name = test_input($_POST["name"]);
    // check if name only contains letters and whitespace
    if (!preg_match("/^[a-zA-Z ]*$/",$name)) {
      $name_error = "Only letters and white space allowed"; 
    }
  }

  if (empty($_POST["email"])) {
    $email_error = "Email is required";
  } else {
    $email = test_input($_POST["email"]);
    // check if e-mail address is well-formed
    if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
      $email_error = "Invalid email format"; 
    }
  }
  
  if (empty($_POST["message"])) {
    $message_error = "Message is required";
  } else {
    $message = test_input($_POST["message"]);
  }
  
  if ($name_error == '' and $email_error == '' and $message_error == '' and $url_error == '' ){
      $message_body = '';
      unset($_POST['submit']);
      foreach ($_POST as $key => $value){
          $message_body .=  "$key: $value\n";
      }
      
      $to = 'ignas.levinskas@mail.com';
      $subject = 'Contact Form Submit';
      if (mail($to, $subject, $message)){
           header('Location: ../front-page.php');
          
          $name = $email = $message = '';
       
      }
        
  }
  
}


function test_input($data) {
  $data = trim($data);
  $data = stripslashes($data);
  $data = htmlspecialchars($data);
  return $data;
}
    
   

 
  
                    <form id="contactform" method="post" action="http://li-designs.com/wp-content/themes/vcs-starter/assets/app.php" >
                    <input name="name" type="text" class="feedback-input" placeholder="Name"  required/> 
                        <span class="error"><?= $name_error ?></span>
                    <input name="email" type="text" class="feedback-input" placeholder="Email" required/>
                        <span class="error"><?= $email_error ?></span>
                    <textarea name="message" type="text" value="<?= $message ?>" class="feedback-input" placeholder="Message" ></textarea>
                        <span class="error"><?= $message_error ?></span>
                    <button name="submit" type="submit" id="contact-submit" data-submit="...Sending">Send</button>
                </form>

0 个答案:

没有答案