简体   繁体   English

Bootstrap联系表单模块问题

[英]Bootstrap contact form module issue

I am having trouble with getting this code to not show a thank you modul for incomplete submissions. 我在获取此代码时遇到麻烦,因为它们未提交不完整的内容,因此无法显示谢谢模块。 I also would like the page redirect to originating page(with a pop up modul for either confirmation or error on the page in a modul would be optimal) or just redirect to the originating page without having to create a new PHP file for every page a contact form is on. 我也想将页面重定向到原始页面(使用弹出模块确认或在页面中的错误是最优的),或者只是重定向到原始页面而不必为每个页面创建新的PHP文件。联系表格已打开。 I have several. 我有一些。

The way it is now it can send mail but it directs to a blank white page with just type on it, and a request to use the browser back button to return to originating page. 现在,它可以发送邮件,但直接进入空白页面,只需键入文字,然后请求使用浏览器的“后退”按钮返回到原始页面。 Also it fires the (Thank you)modul even if in put is in correct. 即使输入正确,它也会触发(谢谢)调制。 would it please be possible to get help with this? 请问有可能得到帮助吗?

<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

And the other part 而另一部分

// 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
}
?>

You just need to play with $success like this: 您只需要像下面这样玩$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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM