[英]form submit is not working when i click button
Why isn't my form working and why are there no errors showing? 为什么我的表单不起作用,为什么没有显示错误? When I click the submit button nothing happens, here is my code: 当我点击提交按钮时没有任何反应,这是我的代码:
<?php
$list_of_product=$p->loadSearchProduct($searchkey);
foreach ($list_of_product as $product) {
echo "<tr>"
.'<form id ="myForm" action = "InsertOrders.php" method = "POST">'
."<td>".$product->prodname."</td>"
."<td>".$product->price."</td>"
."<td>".$product->total." "."Piece(s)"."</td>"
."<td>".$product->remaining_stock." "."Piece(s)"."</td>"
."<td>".$product->sold_stock."</td>"
."<td>"."<input class='form-control' name='qty' type='text' required/>"."</td>"
."<td>"."<button type='submit' id='sub' class='btn btn-primary'>"."<b>Add to List</b>"."</button>"."</td>"
."</form>"
."</tr>";
}
?>
In this case you have several forms with the same id. 在这种情况下,您有几个具有相同ID的表单。
When you click submit, it es not specific witch one is clicked. 当您单击提交时,它不是特定的女巫点击。
EDIT 编辑
$count = 0;
foreach ($list_of_product as $product) {
echo "<tr>"
.'<form id ="myForm" action = "InsertOrders.php" method = "POST">'
."<td>".$product->prodname."</td>"
."<td>".$product->price."</td>"
."<td>".$product->total." "."Piece(s)"."</td>"
."<td>".$product->remaining_stock." "."Piece(s)"."</td>"
."<td>".$product->sold_stock."</td>"
."<td>"."<input class='form-control' name='qty' type='text' required/>"."</td>"
."<td>"."<button type='submit' id='sub".$count."' class='btn btn-primary'>"."<b>Add to List</b>"."</button>"."</td>"
."</form>"
."</tr>";
$count++;
}
When you use an counter, you can check in you InsertOrders.php which one is clicked. 当您使用计数器时,您可以在InsertOrders.php中检查单击哪一个。 Its not the best way, but it will be work. 它不是最好的方式,但它会起作用。
i think if you can use form tags outside of the foreach
, it will submit. 我想如果你可以在foreach
之外使用表单标签,它将提交。 Or else try remove 'id' attribute in your code. 或者尝试在代码中删除'id'属性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.