【问题标题】:Submit a form multiple times in loop循环提交表单多次
【发布时间】:2014-03-18 12:53:56
【问题描述】:

如何在一个循环中多次提交表单。

我想要做的是将发布数据发布到一些用于 SMS 的 3rd 方 API。现在这个第 3 方 SMS 网关只需要 50 号。一口气,我有50多个手机号。

for (int jj=0;jj<=5; jj++)
{
%>

<form name="f" id="ff" action=http://smswebsite.com/api.php  >

<input type=text name=username value="amu" > 

<input type=text name=password value="password" >

<input type=text name=source value="SenderID">

<input type=text name=dmobile value="917417010049" >

<input type=text name=message value="Testing All from hashmi, malik hayat"  > 

</form>

<script type="text/javascript">
      document.getElementById("ff").submit();
    </script>
<%
}
%>

请帮忙

【问题讨论】:

标签: php forms


【解决方案1】:

你遇到了什么问题??? 我看到的 3 个问题

  1. 如果第一次提交表单,页面将离开。所以下一个表单可能无法提交。
  2. 我注意到您的表单 id 保持不变,因此每次执行循环时都会有多个具有相同 id 的表单。使用 id "ff"+jj 的表单标签和 javascript getElementById("ff"+jj) 附加 jj 计数器值。 使用 ajax 将表单发布到,这样您的页面就不会离开。
  3. 在执行文档读取事件时调用 ajax post:因为您可能正在提交一个页面可能尚未呈现的表单。

    $( 文档 ).ready(function() { // 通过ajax提交表单的代码 });

【讨论】:

    【解决方案2】:

    您可以将其作为数组发布。

    <form name="f" id="ff" action=http://smswebsite.com/api.php  >
    for (int jj=0;jj<=5; jj++)
    {
    %>
    <input type=text name="username[]" value="amu" > 
    
    <input type=text name="password[]" value="password" >
    
    <input type=text name="source[]" value="SenderID">
    
    <input type=text name="dmobile[]" value="917417010049" >
    
    <input type=text name="message[]" value="Testing All from hashmi, malik hayat"  > 
    <%
    }
    %>
    
    </form>
    
    <script type="text/javascript">
          document.getElementById("ff").submit();
        </script>
    

    【讨论】:

      猜你喜欢
      • 2012-04-25
      • 1970-01-01
      • 1970-01-01
      • 2015-08-10
      • 1970-01-01
      • 1970-01-01
      • 2018-08-16
      • 2017-12-16
      • 1970-01-01
      相关资源
      最近更新 更多