Cakephp表单尚未提交

时间:2015-11-26 10:54:55

标签: forms cakephp

我正在使用cakephp2.2.7我已经做了很多表单提交维护cakephp标准。这里我有基于循环迭代的多种形式。这是我的代码:

 <style type="text/css">
        .alert {
            padding: 6px;
            margin-bottom: 5px;
            border: 1px solid transparent;
            border-radius: 4px;
            text-align: center;
        }
        input#OrderProductPieces {
            display: inline;
            float: l;
            width: 50px;
        }
        th,td{
            text-align: center;
        }

    </style>

    <div class="page-content-wrapper">
        <div class="page-content">
            <!-- BEGIN PAGE HEADER-->
            <h3 class="page-title">
                Edit this order <small>Edit can't be performed when it delivered</small>
            </h3>

            <!-- END PAGE HEADER-->
            <!-- BEGIN PAGE CONTENT-->
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN EXAMPLE TABLE PORTLET-->
                    <div class="portlet box blue">
                        <div class="portlet-title">
                            <div class="caption">
                                <i class="fa fa-phone"></i>Edit Order
                            </div>
                            <?php echo $this->Session->flash(); ?>
                            <div class="tools">
                                <a href="javascript:;" class="reload">
                                </a>
                            </div>
                        </div>
                        <div class="portlet-body">



                            <table class="table table-striped table-hover table-bordered" id="sample_editable_1">
                                <thead>
                                    <tr>
                                        <th>Product Info </th>
                                        <th>Customer Info</th>
                                        <th > Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    $order = $datas['orders'];
                                    $customer = $datas['customers'];
                                    $order_products = $datas['order_products'];
                                    $product = $datas['products'];
                                    $psettings = $datas['psettings'];
                                    // pr($datas);
                                    // exit;
                                    foreach ($datas['products'] as $index => $product):

                                        echo $this->Form->create('OrderProduct', array(
                                            'inputDefaults' => array(
                                                'label' => false,
                                                'div' => false
                                            ),

                                            'class' => 'form-horizontal',
                                            'novalidate' => 'novalidate',

                                                )
                                        );
                                        ?>
                                        <tr >
                                            <td>
                                                <img src="<?php echo $this->webroot . 'productImages/small/' . $psettings[$index]['small_img'] ?>" width="37" height="34">
                                                <span class="cart-content-count">x <?php
                                                    echo $this->Form->input(
                                                            'pieces', array(
                                                        'class' => 'form-control ',
                                                        'type' => 'text',
                                                        'value' => $order_products[$index]['pieces']
                                                            )
                                                    );
                                                    ?>
                                                </span>

                                                <span>
                                                    <?php echo $product['name'] . ' By ' . $product['writer']; ?>
                                                </span>
                                            </td>

                                            <?php
                                            if ($index == 0):
                                                ?>
                                                <td>
                                                    <?php
                                                    echo $this->Form->input(
                                                            'Customer.name', array(
                                                        'class' => 'form-control ',
                                                        'type' => 'text',
                                                        'value' => $customer['name']
                                                            )
                                                    );
                                                    ?>
                                                    <?php
                                                    echo $this->Form->input(
                                                            'Customer.city', array(
                                                        'class' => 'form-control ',
                                                        'type' => 'text',
                                                        'value' => $datas['city']['name']
                                                            )
                                                    );
                                                    ?>
                                                    <?php
                                                    echo $this->Form->input(
                                                            'Customer.location', array(
                                                        'class' => 'form-control ',
                                                        'type' => 'text',
                                                        'value' => $datas['location']['name']
                                                            )
                                                    );
                                                    ?>
                                                    <?php
                                                    echo $this->Form->input(
                                                            'Customer.mobile', array(
                                                        'class' => 'form-control ',
                                                        'type' => 'text',
                                                        'value' => $customer['mobile']
                                                            )
                                                    );
                                                    ?>
                                                    <?php
                                                    echo $this->Form->input(
                                                            'Customer.alt_mobile', array(
                                                        'class' => 'form-control ',
                                                        'type' => 'text',
                                                        'value' => $customer['alt_mobile']
                                                            )
                                                    );
                                                    ?>
                                                </td>

                                                <?php
                                            else:
                                                ?>
                                                <td> <strong>Same as Above</strong>  </td>

                                            <?php
                                            endif;
                                            ?>

                                            <?php
                                            echo $this->Form->input(
                                                    'Customer.id', array(
                                                'type' => 'hidden',
                                                'value' => $customer['id']
                                                    )
                                            );
                                            ?>
                                            <?php
                                            echo $this->Form->input(
                                                    'Customer.id', array(
                                                'type' => 'hidden',
                                                'value' => $customer['id']
                                                    )
                                            );
                                            ?>
                                            <?php
                                            echo $this->Form->input(
                                                    'OrderProduct.id', array(
                                                'type' => 'hidden',
                                                'value' => $datas['order_products'][$index]['id']
                                                    )
                                            );
                                            ?>

                                            <td >   
                                                <div class="controls center">
                                                    <div class="form-actions">
                                                        <div class="row">
                                                            <div class="col-md-4">
                                                                <?php
                                                                echo $this->Form->button(
                                                                        'Save Changes', array('class' => 'btn green', 'type' => 'submit')
                                                                );
                                                                ?>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <?php
                                                                echo $this->Form->button(
                                                                        'Delete', array('class' => 'btn btn-danger', 'type' => 'submit')
                                                                );
                                                                ?>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <?php
                                                                echo $this->Form->button(
                                                                        'Add New', array('class' => 'btn green', 'type' => 'submit')
                                                                );
                                                                ?>
                                                            </div>
                                                        </div>
                                                    </div>

                                                </div>
                                            </td>
                                        </tr>

                                        <?php
                                        echo $this->Form->end();
                                    endforeach;
                                    ?>

                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- END EXAMPLE TABLE PORTLET-->
                </div>
            </div>
            <!-- END PAGE CONTENT -->
        </div>
    </div>
    <!-- END CONTENT -->

但是当我点击保存更改时,没有提交删除或添加新按钮表单。我可能错过了一个非常基本的问题,但我自己找不到。任何帮助将不胜感激。

1 个答案:

答案 0 :(得分:1)

您必须为每个提交按钮指定一个名称属性。

请尝试以下代码:

<style type="text/css">
        .alert {
            padding: 6px;
            margin-bottom: 5px;
            border: 1px solid transparent;
            border-radius: 4px;
            text-align: center;
        }
        input#OrderProductPieces {
            display: inline;
            float: l;
            width: 50px;
        }
        th,td{
            text-align: center;
        }

    </style>

    <div class="page-content-wrapper">
        <div class="page-content">
            <!-- BEGIN PAGE HEADER-->
            <h3 class="page-title">
                Edit this order <small>Edit can't be performed when it delivered</small>
            </h3>

            <!-- END PAGE HEADER-->
            <!-- BEGIN PAGE CONTENT-->
            <div class="row">
                <div class="col-md-12">
                    <!-- BEGIN EXAMPLE TABLE PORTLET-->
                    <div class="portlet box blue">
                        <div class="portlet-title">
                            <div class="caption">
                                <i class="fa fa-phone"></i>Edit Order
                            </div>
                            <?php echo $this->Session->flash(); ?>
                            <div class="tools">
                                <a href="javascript:;" class="reload">
                                </a>
                            </div>
                        </div>
                        <div class="portlet-body">



                            <table class="table table-striped table-hover table-bordered" id="sample_editable_1">
                                <thead>
                                    <tr>
                                        <th>Product Info </th>
                                        <th>Customer Info</th>
                                        <th > Action</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                    $order = $datas['orders'];
                                    $customer = $datas['customers'];
                                    $order_products = $datas['order_products'];
                                    $product = $datas['products'];
                                    $psettings = $datas['psettings'];
                                    // pr($datas);
                                    // exit;
                                    foreach ($datas['products'] as $index => $product):

                                        echo $this->Form->create('OrderProduct', array(
                                            'inputDefaults' => array(
                                                'label' => false,
                                                'div' => false
                                            ),

                                            'class' => 'form-horizontal',
                                            'novalidate' => 'novalidate',

                                                )
                                        );
                                        ?>
                                        <tr >
                                            <td>
                                                <img src="<?php echo $this->webroot . 'productImages/small/' . $psettings[$index]['small_img'] ?>" width="37" height="34">
                                                <span class="cart-content-count">x <?php
                                                    echo $this->Form->input(
                                                            'pieces', array(
                                                        'class' => 'form-control ',
                                                        'type' => 'text',
                                                        'value' => $order_products[$index]['pieces']
                                                            )
                                                    );
                                                    ?>
                                                </span>

                                                <span>
                                                    <?php echo $product['name'] . ' By ' . $product['writer']; ?>
                                                </span>
                                            </td>

                                            <?php
                                            if ($index == 0):
                                                ?>
                                                <td>
                                                    <?php
                                                    echo $this->Form->input(
                                                            'Customer.name', array(
                                                        'class' => 'form-control ',
                                                        'type' => 'text',
                                                        'value' => $customer['name']
                                                            )
                                                    );
                                                    ?>
                                                    <?php
                                                    echo $this->Form->input(
                                                            'Customer.city', array(
                                                        'class' => 'form-control ',
                                                        'type' => 'text',
                                                        'value' => $datas['city']['name']
                                                            )
                                                    );
                                                    ?>
                                                    <?php
                                                    echo $this->Form->input(
                                                            'Customer.location', array(
                                                        'class' => 'form-control ',
                                                        'type' => 'text',
                                                        'value' => $datas['location']['name']
                                                            )
                                                    );
                                                    ?>
                                                    <?php
                                                    echo $this->Form->input(
                                                            'Customer.mobile', array(
                                                        'class' => 'form-control ',
                                                        'type' => 'text',
                                                        'value' => $customer['mobile']
                                                            )
                                                    );
                                                    ?>
                                                    <?php
                                                    echo $this->Form->input(
                                                            'Customer.alt_mobile', array(
                                                        'class' => 'form-control ',
                                                        'type' => 'text',
                                                        'value' => $customer['alt_mobile']
                                                            )
                                                    );
                                                    ?>
                                                </td>

                                                <?php
                                            else:
                                                ?>
                                                <td> <strong>Same as Above</strong>  </td>

                                            <?php
                                            endif;
                                            ?>

                                            <?php
                                            echo $this->Form->input(
                                                    'Customer.id', array(
                                                'type' => 'hidden',
                                                'value' => $customer['id']
                                                    )
                                            );
                                            ?>
                                            <?php
                                            echo $this->Form->input(
                                                    'Customer.id', array(
                                                'type' => 'hidden',
                                                'value' => $customer['id']
                                                    )
                                            );
                                            ?>
                                            <?php
                                            echo $this->Form->input(
                                                    'OrderProduct.id', array(
                                                'type' => 'hidden',
                                                'value' => $datas['order_products'][$index]['id']
                                                    )
                                            );
                                            ?>

                                            <td >   
                                                <div class="controls center">
                                                    <div class="form-actions">
                                                        <div class="row">
                                                            <div class="col-md-4">
                                                                <?php
                                                                echo $this->Form->button(
                                                                        'Save Changes', array('class' => 'btn green', 'name'=>'save', 'type' => 'submit')
                                                                );
                                                                ?>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <?php
                                                                echo $this->Form->button(
                                                                        'Delete', array('class' => 'btn btn-danger', 'name'=>'delete','type' => 'submit')
                                                                );
                                                                ?>
                                                            </div>
                                                            <div class="col-md-4">
                                                                <?php
                                                                echo $this->Form->button(
                                                                        'Add New', array('class' => 'btn green','name'=>'add','type' => 'submit')
                                                                );
                                                                ?>
                                                            </div>
                                                        </div>
                                                    </div>

                                                </div>
                                            </td>
                                        </tr>

                                        <?php
                                        echo $this->Form->end();
                                    endforeach;
                                    ?>

                                </tbody>
                            </table>
                        </div>
                    </div>
                    <!-- END EXAMPLE TABLE PORTLET-->
                </div>
            </div>
            <!-- END PAGE CONTENT -->
        </div>
    </div>
    <!-- END CONTENT -->

在你的控制器上你可以检查点击了哪个按钮:

    if(isset($this->request->data['OrderProduct']['save'])){

    }
if(isset($this->request->data['OrderProduct']['delete'])){

    }
if(isset($this->request->data['OrderProduct']['add'])){

    }

希望得到这个帮助。

相关问题