I'm struggling with a problem.
I have a foreach inside another foreach -that's not the problem- what happens is that, when I try to put a form inside the nested foreach, my controller doesn't react. When I click on the "+" button it's supposed to add the order and then redirect me to somewhere.php, otherwise, it should redirect me to nowhere.php. It just doesn't redirect me nowhere -without the .php, haha-, meaning that the isset($_POST['do_add'} is not working.
Any ideas?
My controller:
<?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');
}
}
?>
My template:
<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>
Thank you!
var_dump($_POST), and see what you have there.formtag directly aftertbodyis invalid. Browser rebuilds your invalid html and you have not what you expect.