[英]Submit button doesn't work in a form containing table with foreach
I have a form
which contains a table
. 我有一个
form
其中包含一个table
。 In the table
, I used a foreach
to fetch multiple data. 在
table
,我使用了foreach
来获取多个数据。
This is my code: 这是我的代码:
<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>
The values in each row are static except the UseCode
which is an input tag. 除了作为输入标签的
UseCode
之外,每行中的值都是静态的。 The user inputs a number and by pressing the submit
button, the form should post data but it doesn't. 用户输入一个数字,然后按“
submit
按钮,该表单应发布数据,但不发布数据。 I'd like to know why? 我想知道为什么吗? Am I even allowed to do this having a foreach in table?
我什至可以在桌子上放一个foreach来做到这一点? If not, what else I should do to achieve this?
如果没有,我应该怎么做才能做到这一点?
The solution in anyway helps! 无论如何,该解决方案会有所帮助!
JQuery
, Ajax
, anything. JQuery
, Ajax
等等。
You need to give your input element proper name. 您需要给输入元素适当的名称。
Change 更改
<td><input name=userCode id=userCode></td>
To: 至:
<td><input name="userCode[]" id="userCode" value=""/></td>
Please notice the square brackets []
around the name
attribute. 请注意
name
属性周围的方括号[]
。
As you are posting multiple values, you need to post array not a single value. 当您发布多个值时,您需要发布数组而不是单个值。
In backend PHP, just use, 在后端PHP中,只需使用,
echo '<pre>';
print_r($_POST['userCode']);
echo '</pre>';
And you will get all posted values within loop. 然后,您将在循环中获取所有过帐的值。
EDIT: 编辑:
<form>
tag is incorrect. <form>
标记不正确。
Change: 更改:
<from
To 至
<form
Also, closing tag. 另外,关闭标签。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.