【问题标题】:How To Make .php form submit button two actions如何使 .php 表单提交按钮两个动作
【发布时间】:2014-07-13 09:26:04
【问题描述】:

您好,我想制作一个向 XXXXXXX 提交数据并在 mydomain.com 旁边打开一个新选项卡的表单 请帮我把这个..

<form action="XXXXXXXXXX" method="get" style="margin-top: 12px;">
        <label>
            <input type="text" name="user" value="" style="width: 100%" placeholder="Your Code Here" autocomplete="off" autofocus="" required>
        </label>
        <input type="submit" style="width: 84px;margin-top: 10px;" value="Submit" class="submit">
    </form>

请向我发送一些详细信息来执行此操作.. 我首先在官方liker.net 提交按钮上看到了这个..

【问题讨论】:

  • 您是否尝试过使用 JS 向表单添加 onsubmit 操作?在此操作中,您可以打开新窗口,然后执行表单提交。

标签: php forms button tabs submit


【解决方案1】:

试试这个

<form action="XXXXXXXXXX" method="get" style="margin-top: 12px;" target=_blank>
    <label>
        <input type="text" name="user" value="" style="width: 100%" placeholder="Your Code
 Here" autocomplete="off" autofocus="" required>
    </label>

    <input type="submit" style="width: 84px;margin-top: 10px;" value="Submit"

   class="submit">
    </form>

target 属性指定一个名称或关键字,指示在哪里显示提交表单后收到的响应。

【讨论】:

    【解决方案2】:

    为此,您需要使用 jQuery 通过 AJAX 提交表单,并通过 success 回调通过

    window.open(url,'_blank');

    【讨论】:

    • 谢谢我从任何其他网站找到了这个答案!!感谢您的帮助。
    【解决方案3】:

    试试下面的方法

    <form action="XXXXXXXXXX.php" method="get" target="_blank" style="margin-top: 12px;">
    

    【讨论】:

      【解决方案4】:

      如果你想在 Post header("Location: http://www.example.com/") php 函数之后重定向。 如果你想同时打开,你可以使用 JQuery。

      <form>
      
         <input name="text2" type="text" id="text" />
      
      <a class="className" href="#" name="save" id="saveButton">Save</A>
      
      </form>
      

      然后是一些 JavaScript 的东西:

      $(document).ready(function() {
          $("#save").click(function(e) {
              e.preventDefault();
              $.post("sendPhp.php", { textPost : $("#text").val()},
                    function(html) {
                         //open a new window here
                         window.open("mydomain.com");
                    }
          });
      });
      

      【讨论】:

        【解决方案5】:

        无需 Javascript,您只需在表单标签中添加 target="_blank" 属性即可。

          <form action="XXXXXXXXXX" method="get" style="margin-top: 12px;" target=_blank>
                    <label>
                        <input type="text" name="user" value="" style="width: 100%" placeholder="Your Code Here" autocomplete="off" autofocus="" required>
                    </label>
                    <input type="submit" style="width: 84px;margin-top: 10px;" value="Submit" class="submit">
                </form>
        

        以下链接会有所帮助:HTML form target

        【讨论】:

          猜你喜欢
          • 2014-04-11
          • 2017-12-08
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2021-08-11
          • 1970-01-01
          相关资源
          最近更新 更多