對這個問題尋找幾個小時的答案,但我完全堆積,大腦凍結。提交表格後無法擺脫空白的PHP頁面
已成功提交訂閱php窗體與引導模式。一切正常,電子郵件通過,模態顯示只有一秒鐘或更少的空白頁面出現。
我猜這是加載之前form.php文件是一個單獨的文件,但它有一種方法來停止加載空白頁?
這裏是HTML代碼
<form action="form.php" method="post">
<div class="form-group label-floating">
<input name="email" class="control-label form-control text-center" type="text" placeholder="Enter your email address ...">
<button type="submit" class="btn btn-primary" data-toggle="modal" data-target="#myModal">Send</button>
</div>
</form> \t
<!-- Sart Modal -->
\t <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
\t \t <div class="modal-dialog">
\t \t \t <div class="modal-content">
\t \t \t \t <div class="modal-header">
\t \t \t \t \t <button type="button" class="close" data-dismiss="modal" aria-hidden="true">
\t \t \t \t \t \t <i class="material-icons">clear</i>
\t \t \t \t \t </button>
\t \t \t \t \t <h4 class="modal-title">Thank you</h4>
\t \t \t \t </div>
\t \t \t \t <div class="modal-body">
\t \t \t \t \t <p>Thank you for registering, we have added you to the waiting list!
\t \t \t \t \t </p>
\t \t \t \t </div>
\t \t \t \t <div class="modal-footer">
\t \t \t \t \t <button type="button" class="btn btn-danger btn-simple" data-dismiss="modal">Close</button>
\t \t \t \t </div>
\t \t \t </div>
\t \t </div>
\t </div>
<!-- End Modal -->
這裏是PHP代碼
<?php
$to = "[email protected]";
$from = "[email protected]";
$headers = "From: " . $from . "\r\n";
$subject = "New Beta Subscription";
$body = "New user interested in beta program: " . $_POST['email'];
if(filter_var($_POST['email'], FILTER_VALIDATE_EMAIL))
{
if (mail($to, $subject, $body, $headers, "-f " . $from))
{
echo "<script type='text/javascript'>
$(document).ready(function(){
$('#myModal').modal('show');
window.stop();
});
</script>";
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
}
else
{
echo 'There was a problem with your e-mail (' . $_POST['email'] . ')';
}
而且要改變錯誤消息SH也超過了模態,它產生了不知道是否可以從同一索引文件調用兩個模態?
任何幫助非常歡迎! 謝謝,K>
我認爲使用php'json_encode'並在前端使用'Ajax'會更好。 – claudios