形式内的foreach循环的PHP [英] Form inside foreach loop php

查看:65
本文介绍了形式内的foreach循环的PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为一个问题而苦苦挣扎.

I'm struggling with a problem.

我在另一个foreach中有一个foreach-并不是问题-发生的是,当我尝试将表格放入嵌套的foreach中时,我的控制器没有反应.当我单击"+"按钮时,应该添加订单,然后将我重定向到某处.php,否则,它应该将我重定向至nowhere.php.只是没有将我重定向到任何地方-没有.php,哈哈-,这意味着 isset($ _ POST ['do_add'} 不起作用.

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.

有什么想法吗?

我的控制器:

<?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> 

谢谢!

推荐答案

我认为您的问题是这一行:

I think your problem is this line:

<td name = "idCar" value = "<?php echo $car->idCars; ?>"><p><?php echo $car->model; ?></p></td>

我从没听说过直接用表单提交td标签的值...您的意思是这样的事情(在td中创建输入)吗?

I never heard of submitting values of td tag directly with a form... did you mean something like this (create an input inside that td)?

<td><input type="text" name="idCar" value="<?php echo $car->idCars; ?>"</td>

这篇关于形式内的foreach循环的PHP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆