开发者

Forms CakePhp 1 form multiple tables

I have two controllers partners and deals.

When I add deal there is field partner id and in cakephp this generates a dropdown with all the partners. Is there away that if the user wants to add a new partner they could click a checkbox and add form would appear. Tried adding the partner input boxes and yes this creates new partner but it in the deal table it puts the partner id of the selected partner from the drop down not the new partner.

Deal Veiw

<div class="deals form">
<h2>Add New Deal</h2>
<p>Use the form below to fill in the new deals details.</p>
开发者_运维问答<?php echo $form->create('Deal');?>
    <?php
        echo $cksource->create();
        echo $form->input('title');
        echo $form->input('price');
        echo $form->input('market_price');
        echo $form->input('discount');
        echo $form->input('buy_link');
        echo $form->input('image');

        $config['toolbar'] = array(
            array( 'Source', '-', 'Bold', 'Italic', 'Underline', 'Strike', '-','BulletedList' ),
            array( 'Image', 'Link', 'Unlink', 'Anchor' )
        );
        ?><label>Deal Highlights</label><?php
        echo $cksource->ckeditor('highlights', array('config'=>$config));
        ?><label>Deal Fine Print</label><?php
        echo $cksource->ckeditor('fine_print', array('config'=>$config));

        echo $form->input('description');
        ?><hr />
        <h3>Partners Details<?php
        echo $form->input('partner_id');
        echo $form->input('Partner.name');
        echo $form->input('Partner.address1');
        echo $form->input('Partner.city');
        echo $form->input('Partner.county');
        echo $form->input('Partner.postcode');
        echo $form->input('city_id');
        ?><hr />
        <h3>Schedule Deal<?php
        echo $form->input('start');
        echo $form->input('end');
    echo $cksource->end();      
    ?>

<?php echo $form->end(__('Submit', true));?>
</div>

Deal Controller

function admin_add() {
        if (!empty($this->data['Partner']['name'])) {
            $this->data['Deal']['partner_id'] = "";
            if ($this->Deal->Partner->saveAll($this->data)) {
                $this->Session->setFlash(__('The deal has been saved', true));
                $this->redirect(array('controller'=>'deals', 'action' => 'add'));
            } else {
                $this->Session->setFlash(__('The deal could not be saved. Please, try again.', true));
            }
        } else {
            if ($this->Deal->saveAll($this->data)) {
                $this->Session->setFlash(__('The deal has been saved', true));
                $this->redirect(array('controller'=>'deals', 'action' => 'add'));
            }
        }
        $partners = $this->Deal->Partner->find('list');

        $cities = $this->Deal->City->find('list');
        $this->set(compact('partners', 'cities'));
    }

Any Ideas guys? If you know a better way to do it would be happy to hear it,

Thanks Dave


in controller before saving, check if the partner form is not empty, then empty out the $this->data['Deal']['partner_id'];

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜