简体   繁体   English

PHP和JS的“消息发送”确认弹出窗口

[英]“Message send” confirmation popup with PHP and JS

I am just started with PHP and have a rather simple problem I can't seem to figure out. 我刚开始使用PHP,但是有一个似乎无法弄清楚的简单问题。 I have set up a basic PHP script with will send me the content from my sites contact page. 我已经建立了一个基本的PHP脚本,它将通过我的网站联系页面向我发送内容。 The script itself is fine - and so is the validator. 脚本本身很好-验证程序也很好。 Now what I am trying to achieve is getting a simple popup (similar to an alert function in javascript). 现在,我想要实现的是得到一个简单的弹出窗口(类似于javascript中的警报功能)。 Here is my try: 这是我的尝试:

if ($valid) {
        //*isUTF8($subject);
        //*isUTF8($formcontent);
        sendMail();
        $body = $successMarkup . $backMarkup;
        $title = "Form sent";
        @header("location:formsent.php");
    } else {
        $body = $errorMarkup . $errorMarkupEnd . $backMarkup;
        $title = "Form errors";
    }

The file formsent.php I am refering to here only includes basic html markup as well as an javascript alert which is executed as soon as you open the page: 我在这里引用的formsent.php文件仅包括基本的html标记以及打开页面后立即执行的javascript警报:

<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Contact Success</title>
</head>

<body>
<script language="Javascript">
<!--
alert ("Thank you for your message! I will come back to you as soon as possible!")
//-->
</script>
</body>
</html>

Here my question: After I send the filled out contactsheet via the send button I get a popup with the message shown above - BUT to do so it leaves the actual page I am on and shows me only a white screen. 这是我的问题:通过“发送”按钮发送填写好的联系表之后,我弹出一个带有上面显示的消息的窗口-但这样做会离开我的实际页面,并且只显示白屏。

How can I get that popup message implemented without leaving the page I am on? 如何在不离开我所在页面的情况下实现弹出消息?

Try using this one: http://jquery.malsup.com/form/ with jQuery to make an Ajax form submit simple. 尝试使用以下一种方法: http : //jquery.malsup.com/form/和jQuery使Ajax表单提交变得简单。 The examples, shown on that page are quite enough to implement your type of a story. 该页面上显示的示例足以实现您的故事类型。 just put: 刚放:

<script>
$(document).ready(function(){ 
  $('form#form_id').ajaxForm(
     function(data){ 
       alert(data); 
     }
    )
})
</script>

And so everything you need to do in your sendmail script is to echo the needed message, no redirecting required. 因此,您在sendmail脚本中需要做的所有事情就是回显所需的消息,而无需重定向。

header("Location: <url>") results in a proper redirect. header(“ Location:<url>”)会导致正确的重定向。 You need to use Ajax here to send the data (when the user submits it), receive the contents of the popup box and then display it. 您需要在此处使用Ajax发送数据(在用户提交数据时),接收弹出框的内容,然后显示它。

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

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