javascript - 提交按钮在包含带有 foreach 的表格的表单中不起作用

标签 javascript php jquery html ajax

我有一个表单,其中包含一个表格。在table中,我使用foreach来获取多个数据。

这是我的代码:

<from method="post" action="/provider/provider/checkUserCodeValidation">

<table style="direction: rtl;text-align: right;width: 1500px;font-family: tahoma;" align="center">
  <thead>
  <tr>
    <th style="width:5%; ">row</th>
    <th style="width:20%;">Fullname</th>
    <th style="width:30%">Title</th>
    <th style="width: 5%">Number</th>
    <th>Date</th>
    <th>ProCode</th>
    <th>UseCode</th>

  </tr>
  </thead>
  <tbody>
  <?php
  $i=1;
  foreach($Items as $Item)
  {
    echo '<tr>
      <td>'.$i.'</td>
      <td>'.$Item->getUser()->getFullName().'</td>
      <td>'.$Item->getContractTitle().'</td>
      <td>'.$Item->getCount().'</td>
      <td>'.$Item->getCreationDate(true,'Date').'</td>
      <td>'.$Item->getProviderCode().'</td>
      <td><input name=userCode id=userCode></td>

    </tr>';
    $i++;
  }
  ?>
  </tbody>
  <input type="submit" name="Submit" id="submit_butt" value="Submit"/>
</table>


</from>

除了作为输入标记的 UseCode 之外,每行中的值都是静态的。 用户输入一个数字,然后按提交按钮,表单应该发布数据,但事实并非如此。 我想知道为什么?我什至可以在表中使用 foreach 来执行此操作吗?如果没有,我还应该做什么才能实现这一目标?

无论如何,解决方案都有帮助! JQueryAjax,任何东西。

最佳答案

您需要为输入元素指定正确的名称。

改变

<td><input name=userCode id=userCode></td>

致:

<td><input name="userCode[]" id="userCode" value=""/></td>

请注意方括号[]周围name属性。

当您发布多个值时,您需要发布数组而不是单个值。

在后端 PHP 中,只需使用,

echo '<pre>';
print_r($_POST['userCode']);
echo '</pre>';

您将获得循环内所有发布的值。

编辑:

<form>标签不正确。

更改:

<from

<form

还有结束标记。

关于javascript - 提交按钮在包含带有 foreach 的表格的表单中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33146992/

相关文章:

php - 定义默认数组值的最简洁的方式

php - MYSQL 自动填充字段

javascript - 移除 JavaScript 行为

javascript - 如何将选项从 HTML 推送到 JS 中的对象数组?

javascript - 在刷新和/或计时器时在 div 之间切换内容

c# - 将智能卡连接到 Web 应用程序

php - javascript 和 php - 登录脚本

jQuery 扩展列表项在 IE7 中显示略有不同

javascript - jQuery 数学不工作

jquery - 未捕获的类型错误 : Object [object Object] has no method 'live'