Question

The situation is this. We need to be able to create a quote. A quote has for components: Research, Pesel and appointment,cc and registration and set fees. A quote may or may not have each of those but at most can only have 1.

We have a series of forms on one view that we have divided into tabs so that only one can be viewed at a time. The code for the tabs as well as the first form is here:

<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')); ?>

This first form works fine. One that doesn't work is here:

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

and the controller for saving is here:

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'));
    }
    }

Basically we need to be able to save the forms independently of each other. As for the models. Quotes has one of the set fees, cc and registration, pesel, and research and each of those belongs to quotes.

We're new to cakephp and we are at the end of our rope for this. Please help.

Was it helpful?

Solution

All your 5 forms are on the same page, will have the same ID, and submit to the same controller action. So, the first will work, and clicking submit on all others will just submit the first form (ie, the others won't work).

First and foremost, I'd get it working as one big fat long form, without tabs - just so you're dealing with one problem at a time. Once that's working, you've got a few options for splitting your form into tabs. The most straight forward is this:

Open your form before the beginning of the tabs, and close it after the end of the tabs. The submit button will lie outside the tabs, below. But the fields themselves can be distributed amongst the tabs as you see fit.

Users will be able to go from tab to tab, editing fields, then save all fields by clicking the submit button outside of the tabs, below.

So that'd look like this:

<?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')); ?>

Your other options would be to make each tab a separate form that submits to a separate controller action, and / or use ajax. But the previous way I described should be easiest.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top