【问题标题】:php success message handlingphp成功消息处理
【发布时间】:2013-05-30 19:34:24
【问题描述】:

我有一个表单,我用 Jquery 向下滑动,还有一个 php 脚本,我需要在将数据发送到服务器 (php) 后重定向,并且还显示“成功”消息(不是在 url 中,而是在表单中) .
我正在这样做(正如我在 stackoverflow 中找到的那样):

header("location:VIP.php?response=1");

并在 VIP.php 之后:

if (isset ($_GET['response']))
{
    if ($_GET['response']=="1")
    {
      echo "Se ha registrado con éxito"; //this is my success message (spanish)
    }
}

它就像一个魅力,唯一的事情是我需要设计这个,它显示在身体的左上角......我不知道如何让它以表格(或任何其他具体的div)

如果有人能启发我,我将不胜感激。谢谢!

【问题讨论】:

  • 想向我们展示您的表格吗?想告诉我们更多关于 jQuery 和 PHP 的交互吗?
  • 将 php 代码块的位置移动到页面结构中您希望消息输出的任何位置。

标签: php forms redirect get


【解决方案1】:

这样做:

if (isset ($_GET['response']))
{
   if ($_GET['response']=="1")
   {
       $msg = "Se ha registrado con éxito"; //this is my success message (spanish)
   }
}

然后在您的 html 页面中的某个位置(例如在您的表单中):

<?php if( $msg ): ?><div class="notice"><?php echo $msg ?></div><?php endif; ?>

【讨论】:

  • 不要忘记在 if() 结构之外初始化 $msg,否则如果未设置 msg,您只会导致未定义变量警告。
  • 其实完整的解决方案应该是按照&lt;?php if( $msg ): ?&gt;&lt;div class="notice"&gt;&lt;?php echo $msg ?&gt;&lt;/div&gt;&lt;?php endif; ?&gt;的思路
猜你喜欢
  • 2020-06-11
  • 2017-07-26
  • 2021-11-06
  • 1970-01-01
  • 2021-09-23
  • 2011-09-23
  • 2015-04-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多