我正在努力解决一个问题。内部foreach循环php
我有一个foreach里面的另一个foreach - 这不是问题 - 会发生的是,当我尝试在嵌套的foreach中放置一个表单时,我的控制器没有反应。当我点击“+”按钮时,它应该添加顺序,然后将我重定向到somewhere.php,否则,它应该将我重定向到nowhere.php。它只是不会重定向我无处 - 没有.php,哈哈,这意味着isset($_POST['do_add'}
不起作用。
任何想法?
我的控制器:
<?php
$br = new Brand;
$ord = new Order;
$temp = new Template('templates/menu.php');
$temp->br = $br->getAllBrands();
$temp->car = new Car;
echo $temp;
if(isset($_POST['do_add'])) {
$idPlate = $_POST['idCars'];
if ($ped->addCar($idCar)) {
redirect('somewhere.php');
} else {
redirect('nowhere.php');
}
}
?>
我的模板:
<table class = "table">
<?php foreach ($brands as $brand): ?>
<thead class = "thead-inverse">
<tr>
<th> <?php echo $brand->name; // these are just some car brands ?> </th>
</tr>
</thead>
<?php foreach ($cars->getCars($brand->idBrands) as $car): // here I get all the cars ordered by brands ?>
<tbody>
<form role = "form" method = "post" action = "carList.php">
<tr>
<td name = "idCar" value = "<?php echo $car->idCars; ?>"><p><?php echo $car->model; ?></p></td>
<td>
<button name = "do_add" type = "submit">+</button>
</td>
</tr>
</form>
</tbody>
<hr>
<?php endforeach; ?>
<?php endforeach; ?>
</table>
谢谢!
表单是否填充了预期值?如果是这样,你的问题只是当你试图在你的控制器中检索de值。尝试'var_dump($ _ POST)',看看你有什么。 – Clyff
在'tbody'后面直接有'form'标签无效。浏览器重建你的无效html,你没有期望。 –
等等..为什么我没有看到这种形式的任何输入?这只是一个提交按钮' - ' – Clyff