0

情况是这样的。我们需要能够创建报价。报价包含组件:研究、Pesel 和预约、抄送和注册和设置费用。一个报价可能有也可能没有,但最多只能有 1 个。

我们在一个视图上有一系列表单,我们将这些表单划分为选项卡,以便一次只能查看一个。选项卡的代码以及第一种形式在这里:

<script>
    $(function() 
    {`
         $( "#tabs" ).tabs();
    });
    $(function() {
    $( "#accordion" ).accordion({
        active: false,
        collapsible: true,
        heightStyle: "content"

    });
});

</script>

    <div id="tabs">
    <ul>
        <li><a href="#tabs-1">Quote Info</a></li>
        <li><a href="#tabs-2">Research</a></li>
        <li><a href="#tabs-3">CC and Registration</a></li>
        <li><a href="#tabs-4">PESEL and appointment</a></li>
        <li><a href="#tabs-5">Other Fees</a></li>
    </ul>

<div id="tabs-1">
<?php echo $this->Form->create('Quote'); ?>
        <p>
        <h3>Quote Information</h3>
        <p>
<fieldset>
    <div id="hide"><?php echo $this->Form->input('date', array('dateFormat' => 'DMY'));?></div>
    <?php
    echo $this->Form->input('description');
            echo $this->Form->input('quote_accepted');
    echo $this->Form->input('research_accepted');
    echo $this->Form->input('cc_accepted');
    echo $this->Form->input('pesel_accepted');
    echo $this->Form->input('setfees_accepted');
    echo $this->Form->input('total', array('value' => '0'));
?>
</fieldset>

<?php echo $this->Form->end(__('Submit')); ?>

第一种形式工作正常。一个不起作用的是这里:

<div id="tabs-5">

        <?php echo $this->Form->create('Quote'); ?>
        <h3><?php echo __('Other Fees'); ?></h3>
    <table>
        <tbody>
            <tr>
                <th>Item</th>
                <th>Quantity</th>
                <th>Initial Price</th>
                <th>Client Price</th>
                <th>Total</th>
            </tr>  
            <tr>
                <td><h5>Children under 18</h5></td>
                <td> <?php echo $this->Form->input('Setfee.children_quantity', array('label' => ''));?> </td>
                <td>$900</td>
                <td><input type="text"> </td>
                <td> <?php echo $this->Form->input('Setfee.children_total', array('label' => ''));?> </td>
            </tr>
                <tr>
                <td><h5>Relatives of Confirmed Citizens</h5></td>
                <td> <?php echo $this->Form->input('Setfee.relatives_quantity', array('label' => ''));?> </td>
                <td>$900</td>
                <td><input type="text"> </td>
                <td> <?php echo $this->Form->input('Setfee.relatives_total', array('label' => ''));?> </td>
            </tr> 
            <tr>
                <td><h5>Registration of One Birth or Marriage Certificate</h5></td>
                <td> <?php echo $this->Form->input('Setfee.reg_birth_marriage_quantity', array('label' => ''));?> </td>
                <td>$50</td>
                <td><input type="text"> </td>
                <td> <?php echo $this->Form->input('Setfee.reg_birth_marriage_total', array('label' => ''));?> </td>
            </tr> 
            <tr>
                <td><h5>Registration of Birth and Marriage Certificate Altogether</h5></td>
                <td> <?php echo $this->Form->input('Setfee.reg_birth_marriage_together_quantity', array('label' => ''));?> </td>
                <td>$50</td>
                <td><input type="text"> </td>
                <td> <?php echo $this->Form->input('Setfee.reg_birth_marriage_together_total', array('label' => ''));?> </td>
            </tr> 
             <tr>
                <td><h5>Standard Fees</h5></td>
                <td></td>
                <td></td>
                <td></td>
                <td> <?php echo $this->Form->input('Setfee.standard_fee_total', array('label' => ''));?> </td>
            </tr> 
        <tr>
        <td> <h5><?php echo $this->Form->input('Setfee.set_fees_total');?></h5></td>
        <td></td>
        <td></td>
        <td></td>
        <div id='hide' ><?php echo $this->Form->input('Setfee.quote_id');?></div>
        <td><?php echo $this->Form->end(__('Submit')); ?></td>
        </tr>     
        </tbody>
    </table>
        </div>

保存的控制器在这里:

public function makeQuote()
    {
        $this->loadModel('Applicant');
        $this->LoadModel('ApplicantQuote');
        $this->LoadModel('Setfee');

        //retrieves the applicants chosen from the view_quotes page
        $args = $this->params['url'];
        $applicants = $this->Applicant->find('all', array('conditions' => array('id' => $args), 
            'order' => 'first_name ASC', 'recursive' => -1));


        $this->set(compact('applicants'));

        if ($this->request->is('post')) 
            {
            $this->Quote->create();

            if($this->Quote->saveall($this->request->data))
            {
                $this->Session->setflash(__('quote saved'));
    }
    }

基本上我们需要能够彼此独立地保存表单。至于型号。报价具有固定费用之一,抄送和注册,pesel 和研究,每一个都属于报价。

我们是 cakephp 的新手,我们已经走到了尽头。请帮忙。

4

1 回答 1

0

您的所有 5 个表单都在同一页面上,具有相同的 ID,并提交到相同的控制器操作。因此,第一个将起作用,在所有其他表单上单击提交只会提交第一个表单(即,其他表单将不起作用)。

首先也是最重要的,我会让它作为一个大而长的表格工作,没有标签 - 只是这样你一次处理一个问题。一旦这样做了,您就有几个选项可以将表单拆分为选项卡。最直接的是这样:

在选项卡开始前打开表单,在选项卡结束后关闭表单。提交按钮将位于选项卡之外,如下所示。但是字段本身可以在您认为合适的情况下分布在选项卡中。

用户将能够从一个选项卡转到另一个选项卡,编辑字段,然后通过单击下面选项卡外部的提交按钮来保存所有字段。

所以看起来像这样:

<?php echo $this->Form->create('Quote'); ?>

<div id="tabs-1">
    // A bunch of form fields go here
</div>
<div id="tabs-2">
    // A bunch of other form fields go here, etc
</div>

<?php echo $this->Form->end(__('Submit')); ?>

您的其他选择是使每个选项卡成为一个单独的表单,提交给单独的控制器操作,和/或使用 ajax。但是我之前描述的方法应该是最简单的。

于 2013-09-23T11:34:54.163 回答