我有一个表单
,其中包含一个表格
。在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 来执行此操作吗?如果没有,我还应该做什么才能实现这一目标?
无论如何,解决方案都有帮助! JQuery
、Ajax
,任何东西。
最佳答案
您需要为输入元素指定正确的名称。
改变
<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/