提交无效后的PHP模式

时间:2017-11-19 19:11:24

标签: php forms

关于@ss联系表格的问题。 提交表单后,bootstrap弹出窗口会显示确认信息,但显然没有显示。

这是我的代码:

<?php 

if(isset($_POST['submit'])) {     
// EDIT THE 2 LINES BELOW AS REQUIRED

$email_to = "info@***.com";

// EDIT THE 2 LINES BELOW AS REQUIRED
$sender = $_POST['email'];

$name = $_POST['name']; // required
$email = $_POST['email']; // required
$object = $_POST['object'];
$message = $_POST['message'];


$email_message = "Form details below.\n\n";

$email_subject = "Contact details - $name";

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)."\n";
$email_message .= "object: ".clean_string($object)."\n";
$email_message .= "Message: ".clean_string($message)."\n";


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

if($sent){
//         echo "<script>alert('Thank you for submitting your details, We will be in touch as per your request.')
//         location.replace('contact.html')
// </script>";
    echo "<script>$('#thankyouModal').modal('show')</script>";
}
else {
echo "<script>alert('Sorry! Something went wrong')
        location.replace('contact.html')
</script>";

  }
}
?>

<html>
    <head>  
    <title></title>
    <!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>

<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>

    </head>
    <body>

<div class="modal fade" id="thankyouModal" tabindex="-1" role="dialog">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header text-center">
        <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
        <h2 class="modal-title text-center" style="font-weight: 600;">Thank you for Contact Us!</h2>
      </div>
      <div class="modal-body text-center" style="background-color: #59ABE3;">
        <p style="font-weight: 600; color: #fff; font-size: 18px;">Thanks for getting in touch!</p>
      </div>
      <div class="modal-footer" style="background-color: #59ABE3; border-top: 0px solid #fff;">
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
      </div>
    </div><!-- /.modal-content -->
  </div><!-- /.modal-dialog -->
</div><!-- /.modal -->

    </body>
</html>

表单通过提交按钮将我发送到cont.php,然后我得到空白的cont.php页面。

我希望有人有答案。 先谢谢你们!

1 个答案:

答案 0 :(得分:0)

尝试将(document).ready函数添加到您的JS代码段。

echo "<script>
$(document).ready(function(){
$('#thankyouModal').modal('show');
});
</script>";

并在</head>标记之前移动整个PHP脚本,因为您不想在初始化jQuery之前调用函数。

然后你应该加载你的模态:

this

相关问题