【问题标题】:Form to redirect to a particular URL重定向到特定 URL 的表单
【发布时间】:2017-10-04 01:24:00
【问题描述】:

我需要一个带有一个输入(例如“数字”)的表单,在 sumbit 将浏览器重定向到 http://staticurl/[number].html 之后 我该怎么办?

【问题讨论】:

  • 发布您的代码。
  • 做html表单教程了解表单动作和表单方法
  • “我需要” 没有任何迹象表明自己试图解决问题就像乞求被否决和关闭。
  • 可以使用top.location.href 进行重定向(preventDefault 后的javascript 用于停止标准表单操作);表单本身可以使用 action 属性重定向,但您还没有提供详细的 PR 代码。

标签: javascript php html forms


【解决方案1】:
header('location:  http://staticurl/'.$_POST['number'].'html');

也许?

【讨论】:

    【解决方案2】:

    假设一个 HTML 表单像

    <form action="" method="POST">
        <input type="number" name="number">
        <input type="submit" name="submit" value="submit">
    </form>
    

    现在使用 php 你可以重定向

    <?php 
        if(isset($_POST['submit'])){
            header("Location: http://staticurl/".$_POST['number'].".html");
        }
     ?>
    

    如果 header() 返回任何错误,那么您可以使用 php 中的 javascript 来完成,例如

    <?php 
        if(isset($_POST['submit'])){
            echo '
                <script>
                    window.location.href = "http://staticurl/'.$_POST['number'].'.html";
                </script>
            ';
        }
     ?>
    

    在处理表单数据之前对其进行验证。

    【讨论】:

      【解决方案3】:

      解决了

      <script type="text/javascript">
      function goTo()
      {
          var NUM= document.forms[0].NUM.value;
          var URL = 'http://staticurl/'
          window.location = URL+NUM+'.jpg';
          return false;
      }
      </script>
      

      <form action="" method="get" onsubmit="return goTo()">
      

      【讨论】:

        猜你喜欢
        • 2016-12-26
        • 2018-02-15
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-06-12
        相关资源
        最近更新 更多