简体   繁体   English

提交表单后,在同一弹出窗口中显示成功消息

[英]Display success msg inside same popup window after form submission

Having trouble figuring out a way to keep my popup/lightbox window open after a user submits a form. 在解决用户提交表单后使弹出窗口/灯箱窗口保持打开状态的方法时遇到麻烦。 I'm a complete beginner at PHP. 我是PHP的完整入门者。 Right now I just have it going to a message that says "thank you" 现在,我只想说一条消息:“谢谢”

If you'd like to see it live, go to http://druvocals.com/dv And click the envelope icon at the top right. 如果您想观看直播,请访问http://druvocals.com/dv ,然后点击右上角的信封图标。

Basically, I want that popup window to stay up after the user clicks "Send" and then just have a little thank you message and then maybe a button that says "Close" and then they will just be right back on the home page. 基本上,我希望在用户单击“发送”后弹出窗口保持打开状态,然后只显示一些感谢消息,然后单击“关闭”按钮,然后他们将立即回到主页。 Here's my php code for the form. 这是表格的我的php代码。

   <?php

$EmailFrom = "DruVocals";
$EmailTo = "dru.sing.vocals@gmail.com";
$Subject = "DruVocals";
$Name = Trim(stripslashes($_POST['name'])); 
$Email = Trim(stripslashes($_POST['email'])); 
$Message = Trim(stripslashes($_POST['text'])); 

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "thanks";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

Since the "popup" is not actual popup (ie separate browser window/tab), upon submiting the form browser goes to forms action url. 由于“弹出窗口”不是实际的弹出窗口(即单独的浏览器窗口/选项卡),因此在提交表单时,浏览器会转到表单操作网址。

A common solution is upon button click to not submit actual form, but collect necessary data and send it to server via javascripts ajax call. 一种常见的解决方案是单击按钮时不提交实际表单,而是收集必要的数据并通过javascripts ajax调用将其发送到服务器。 That way everything end user sees stays the same. 这样,最终用户看到的一切都保持不变。 You can display thank you message, error message, close button and anything else depending on what response you get from the server with ajax. 您可以显示感谢消息,错误消息,关闭按钮以及其他内容,具体取决于您使用ajax从服务器获得的响应。

And all of this have very little to do with PHP. 所有这些与PHP几乎没有关系。

Just redirect to the homepage with some variable. 只需使用一些变量重定向到首页即可。 Like: 喜欢:

header('Location: http://druvocals.com/dv/?sended='.$success);

And to the homepage: 并转到主页:

<? if( isset($_GET['sended']) && $_GET['sended'] == true ){ ?>
 Some html, like the email sender form popup, just with the message what you want.
<?}?>

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

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