发布表单,等待十秒钟并重定向到

Post form, wait ten seconds and redirect to

本文关键字:十秒 重定向 等待 布表单 表单      更新时间:2023-09-26

我有一个页面需要执行以下步骤:

步骤 1 - 通过POST接收 URL 地址、名称、值、编号和 ID

第 2 步 - 等待 10 秒

第 3 步 - 将(也通过邮寄)通过邮寄收到的以下信息发送(也通过邮寄):名称、值、数字和 ID 到通过邮寄收到的 URL

步骤4 - 重定向到收到帖子的URL,然后在屏幕中打印帖子。

为此,我使用了下面的代码,但是出现了任何问题,因为重定向URL中的打印应该带来帖子信息是空的,所以看起来由于任何原因信息都没有正确发布。

有人可以告诉我我做错了什么吗?

法典:

HTML - 创建要发布的表单:

<form id="ret" name="return_url" method="post" action="<?php print_r($_POST['url']);?>">
 <input type="hidden" name="name" value="<?php print_r($_POST['name']);?>" />
 <input type="hidden" name="value" value="<?php print_r($_POST['value']);?>" />
 <input type="hidden" name="num" value="<?php print_r ($_POST['num']);?>" />
 <input type="hidden" name="ID" value="<?php print_r($_POST['ID']);?>" />
 <input type="hidden" name="status" value="OK" />
</form>

将发布的 url 内容添加到将在 Javascript (PHP) 中使用的 var $retorno

<?php
    $retorno = $_POST['url'];
?>

启动计数器,提交表单并重定向(使用javascript):

<script language="javascript" type="text/javascript">
  window.onload = function() {
    function countdown() {
      if (typeof countdown.counter == 'undefined') {
        countdown.counter = 10; // initial count
      }
      if (countdown.counter > 0) {
        document.getElementById('count').innerHTML = countdown.counter--;
        setTimeout(countdown, 1000);
      }
      else {
        document.getElementById("ret").submit();
        location.href = '<?php echo $retorno?>';
      }
    }
    countdown();
  };
</script>

你的代码有很多问题。

1.您在应该使用echo的地方使用print_r

<form id="ret" name="return_url" method="post" action="<?php print_r($_POST['url']);?>">

在上面的行中,print_r 将以无效的方式输出$_POST['url']的内容,该内容将作为action属性值无效。查看生成的页面的 HTML 源代码。

这应该重写为:

<form id="ret" name="return_url" method="post" action="<?php echo $_POST['url']; ?>">

你对所有输入值都犯了同样的错误。操作值尤其重要,因为它必须是表单发布地址。

2. 您提交表单,但也重定向页面

表单submit()和重定向之间存在冲突location.href

只需删除location.href线即可。如果您的 HTML 表单配置正确,JavaScript submit()会将浏览器发送到 action 属性中定义的页面。

最后,我建议您查看jQuery库以使JavaScript编码更容易。