【发布时间】:2012-02-16 07:43:14
【问题描述】:
我在 the-form-page.php 上的表单在提交到 handlerpage.php 时被 POST。
POST 之后我需要重定向回 the-form-page.php。
嗯,这绝对没问题,目前正在工作。用户在 the-form-page.php 上填写表格,按“提交”,POST 数据由 handlerpage.php 处理(一些计算并将结果写入 mysql 数据库),然后我使用 window.location=
成功重定向回 the-form-page.php问题是在 handlerpage.php 上从 the-form-page.php 的 POST 中提交的数据创建的大数据需要返回到 the-form-page.php 并且原始表单数据也需要返回到 the-form-page.php 以便用户看到“啊,这是我的原始数据和结果出来了。'
我不能使用 GET 以编程方式返回到 the-form-page.php -- 数据对于 GET 参数来说太大了。 而且我想坚持使用 window.location= 作为重定向方法(如果可能的话)。
如何重定向回 the-form-page.php 并显示用户的原始数据以及 handlerpage.php 的处理结果?
注意:重新架构以将 the-form-page.php 和 handlerpage.php 结合起来不是一种选择。
我已经完成了,在处理完 handlerpage.php 上的数据后,我现在成功返回 the-form-page.php,我只是需要用 handlerpage.php 上创建的原始数据和新数据重新填充它。
【问题讨论】:
-
对于重定向,使用 headers。要取回表单数据,请使用 sessions。
-
header() 的问题是,一旦出现第一个“echo”或任何其他类型的浏览器输出,您就不能再使用 header() 而不会收到“header already sent”错误。 window.location 避免了它。
-
您可以使用输出缓冲,或者,在重定向部分之外处理消息。