Bootstrap联系表单模块问题

时间:2015-10-08 17:36:51

标签: javascript php

我无法让此代码显示不完整提交的感谢模块。我也希望页面重定向到原始页面(弹出模块用于模块中页面上的确认或错误将是最佳的)或者只是重定向到原始页面而不必为每个页面创建新的PHP文件联系表格已开启。我有几个。

现在它可以发送邮件的方式,但它会指向一个空白的白页,上面只有类型,并且请求使用浏览器后退按钮返回到原始页面。即使在put中也是正确的,它也会触发(谢谢)模块。请问有可能得到这方面的帮助吗?

<form class="o-form" id="contactForm" action="php/contact.php" method="post">
                          <input type="email" name="senderEmail" id="senderEmail" required="required" placeholder="email">
                           <textarea name="message" id="message" required="required placeholder="message"></textarea>
                          <input type="submit" value="send" class="send-button">
                      </form>
                  </div>
              </div>
          </div>
      </div>
      <div class="copyright">
         <span>
           anthonygallina
         </span>
      </div>
   </footer>
   <div class="th-popup">
       <div class="massage-th">
           <h1>Thank You!</h1>
           <p>We apreciate your visit to our home page. We will contact you soon!</p>
       </div>
   </div>

<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/all.js"></script>
<script src="js/jquery.mixitup.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/idangerous.swiper.min.js"></script>
</body>
</html>

<?php

另一部分

// Define some constants
define( "RECIPIENT_NAME", "YOURNAME" );
define( "RECIPIENT_EMAIL", "YOUR@EMAIL.net" );
define( "EMAIL_SUBJECT", "Visitor Message" );

// Read the form values
$success = false;
$senderEmail = isset( $_POST['senderEmail'] ) ? preg_replace( "/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderEmail'] ) : "";
$message = isset( $_POST['message'] ) ? preg_replace( "/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message'] ) : "";

// If all values exist, send the email
if ( $senderEmail && $message ) {
  $recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
  $headers = "From: " . $senderEmail . " <" . $senderEmail . ">";
  $success = mail( $recipient, EMAIL_SUBJECT, $message, $headers );
}

// Return an appropriate response to the browser
if ( isset($_GET["ajax"]) ) {
  echo $success ? "success" : "error";
} else {
?>
<html>
  <head>
    <title>Thanks!</title>
  </head>
  <body>
  <?php if ( $success ) echo "<p>Thanks for sending your message! We'll get back to you soon.</p>" ?>
  <?php if ( !$success ) echo "<p>There was a problem sending your message. Please try again.</p>" ?>
  <p>Click your browser's Back button to return to the page.</p>
  </body>
</html>
<?php
}
?>

1 个答案:

答案 0 :(得分:1)

  

您只需要像$success这样玩:

<?php
// Define some constants
define("RECIPIENT_NAME", "YOURNAME");
define("RECIPIENT_EMAIL", "YOUR@EMAIL.net");
define("EMAIL_SUBJECT", "Visitor Message");

// Read the form values
$success = false;
$senderEmail = isset($_POST['senderEmail']) ? preg_replace("/[^\.\-\_\@a-zA-Z0-9]/", "", $_POST['senderEmail']) : "";
$message = isset($_POST['message']) ? preg_replace("/(From:|To:|BCC:|CC:|Subject:|Content-Type:)/", "", $_POST['message']) : "";

// If all values exist, send the email
if ($senderEmail && $message) {
    $formSubmitted = true;
    $recipient = RECIPIENT_NAME . " <" . RECIPIENT_EMAIL . ">";
    $headers = "From: " . $senderEmail . " <" . $senderEmail . ">";
    $success = mail($recipient, EMAIL_SUBJECT, $message, $headers);
}

// Return an appropriate response to the browser
if (isset($_GET["ajax"])) {
    echo $success ? "success" : "error";
} ?>
<!--Your contact.php page-->

<form class="o-form" id="contactForm" action="php/contact.php" method="post">
    <input type="email" name="senderEmail" id="senderEmail" required="required" placeholder="email">
    <textarea name="message" id="message" required="required placeholder=" message"></textarea>
    <input type="submit" value="send" class="send-button">
</form>
</div>
</div>
</div>
</div>
<div class="copyright">
         <span>
           anthonygallina
         </span>
</div>
</footer>
<div class="th-popup">
    <div class="massage-th">
        <h1>Thank You!</h1>

        <p>We apreciate your visit to our home page. We will contact you soon!</p>
    </div>
</div>

<script src="js/jquery-1.11.1.min.js"></script>
<script src="js/all.js"></script>
<script src="js/jquery.mixitup.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/idangerous.swiper.min.js"></script>
<script>

    <?php
     if($formSubmitted)
     {
         if ($success)
         {
            $msg="<p>Thanks for sending your message! We'll get back to you soon.</p>";
         }
         else
         {
            $msg="<p>There was a problem sending your message. Please try again.</p>";
         }
     //Open your confirmation or error model here using $msg
     }
     ?>
</script>
</body>
</html>