user2358060
user2358060

Reputation: 1

CakePHP form not posting data

I am trying to use 2 forms in CakePHP in a tab.

I am trying to use action 'financial_day_begin' in the view.

The controller has 2 functions 'financial_day' and 'financial_bill_day' both of which I am calling in 'financial_day_begin'.

Following is the code for view, financial_day_begin.ctp:

<div class="panel">
    <h2><?php echo sprintf(__("End of Business %s", true), $financial['Financial']['_end_of_business_date']); ?></h2>
    <div class="panel-content">
        <?php echo $this->element('reports/tabs'); ?>
        <div id="search" class="form">
            <?php
                echo $this->Form->create('Finbill', array('url' => array(
                        'controller' => 'reports',
                        'action' => 'financial_day_begin'
                    )));
                echo $this->Form->input('end_of_bill_date', array(
                    'label' => __("Select Cycle", true),
                    'options' => $finbillList
                ));
                echo $this->Form->end();
            ?>
        </div>
        <?php
            $labels = array(
                'billed_in_cycle'
            );

            echo $this->Html->tag('h3', __("Billed", true));
            echo $this->DataTable->create(array('class' => 'vertical'));

            foreach($labels as $key => $label) {
                if(is_numeric($key)) {
                    $key = $label;
                    $label = Inflector::humanize($label);
                }

                echo $this->DataTable->createRow();
                echo $this->DataTable->createHeader(__($label, true));
                echo $this->DataTable->createCell(sprintf("$%s", number_format($finbill['Finbill'][$key], 2)), array('class' => 'value'));
                echo $this->DataTable->endRow();
            }

            echo $this->DataTable->end();

        ?>
        <div id="search" class="form">
            <?php
                echo $this->Form->create('Financial', array('url' => array(
                        'controller' => 'reports',
                        'action' => 'financial_day_begin'
                    )));
                echo $this->Form->input('end_of_business_date', array(
                    'label' => __("Select Day", true),
                    'options' => $financialList
                ));
                echo $this->Form->end();
            ?>
        </div>
        <?php
            $labels = array(
                'billed_adjustments' => 'Adjustments'
            );

            echo $this->Html->tag('h3', __("Adjustments", true));
            echo $this->DataTable->create(array('class' => 'vertical'));

            foreach($labels as $key => $label) {
                if(is_numeric($key)) {
                    $key = $label;
                    $label = Inflector::humanize($label);
                }

                echo $this->DataTable->createRow();
                echo $this->DataTable->createHeader(__($label, true));
                echo $this->DataTable->createCell(sprintf("$%s", number_format($financial['Financial'][$key], 2)), array('class' => 'value'));
                echo $this->DataTable->endRow();
            }

            echo $this->DataTable->end();

            $labels = array(
                'payments',
                'payment_reversals',
                'payments_net' => 'Net Payments'
            );

            echo $this->Html->tag('h3', __("Payments", true));
            echo $this->DataTable->create(array('class' => 'vertical'));

            foreach($labels as $key => $label) {
                if(is_numeric($key)) {
                    $key = $label;
                    $label = Inflector::humanize($label);
                }

                echo $this->DataTable->createRow();
                echo $this->DataTable->createHeader(__($label, true));
                echo $this->DataTable->createCell(sprintf("$%s", number_format($financial['Financial'][$key], 2)), array('class' => 'value'));
                echo $this->DataTable->endRow();
            }

            echo $this->DataTable->end();
        ?>
    </div>
</div>
<?php
    $this->Html->script("reports/financial_day", array('inline' => false));
?>

Here's my controller, reports_controller.php:

<?php
    class ReportsController extends AppController {

        var $name = 'Reports';
        var $uses = array(
            'Subscriber',
            'Financial',
            'Finbill',
            'Trend'
        );

        var $presetVars = array(
            array(
                'field' => 'posted',
                'type' => 'value'
            ),
            array(
                'field' => 'end_of_business_date',
                'type' => 'value'
            ),
            array(
                'field' => 'end_of_bill_date',
                'type' => 'value'
            ),
            array(
                'field' => 'start_id',
                'type' => 'value'
            ),
            array(
                'field' => 'end_id',
                'type' => 'value'
            ),
            array(
                'field' => 'month_year',
                'type' => 'value'
            )
        );

        function index() {
            $subscriber = $this->Subscriber->find('first', array(
                'contain' => false,
                'order' => array('posted' => 'desc')
            ));

            $this->set(compact('subscriber'));
        }

        function financial_bill_day() {
            $this->Prg->commonProcess('Finbill');

            $searchConditions = $this->Finbill->parseCriteria($this->passedArgs);

            $finbill = $this->Finbill->find('first', array(
                'conditions' => $searchConditions,
                'contain' => false,
                'order' => array('end_of_bill_date' => 'desc')
            ));

            $finbillList = $this->Finbill->find('list', array(
                'contain' => false,
                'fields' => array(
                    'end_of_bill_date'
                ),
                'order' => array('end_of_bill_date' => 'desc')
            ));

            $this->set(compact('finbill', 'finbillList'));
        }

        function financial_day() {
            $this->Prg->commonProcess('Financial');

            $searchConditions = $this->Financial->parseCriteria($this->passedArgs);
            $financial = $this->Financial->find('first', array(
                'conditions' => $searchConditions,
                'contain' => false,
                'order' => array('end_of_business_date' => 'desc')
            ));

            $financialList = $this->Financial->find('list', array(
                'contain' => false,
                'fields' => array(
                    'end_of_business_date',
                    '_end_of_business_date'
                ),
                'order' => array('end_of_business_date' => 'desc')
            ));

            $this->set(compact('financial','financialList'));
        }

        function financial_day_begin() {
            $this->financial_day();

            $this->financial_bill_day();

            $this->set(compact('finbill','finbillList','financial','financialList'));
        }

    }
?>

The problem is, when I try to select the input values from the drop down in my select box, nothing is posted (as per address bar in my browser). I am guessing this is why new values are not called either.

Is there some place outside the ctp file where we need to define the actions that should be called?

Any help on this problem is much appreciated.

Upvotes: 0

Views: 2012

Answers (1)

P&#225;draig Galvin
P&#225;draig Galvin

Reputation: 1155

Those forms will submit post requests, not get requests, so the data won't be in the URL. If you want to see what data is being submitted try adding debug($this->data) at the start of your controller action. $this->passedArgs should probably be replaced by $this->data also. If you want your forms to use get requests you should change them like this:

echo $this->Form->create('Finbill', array(
    'url' => array(
        'controller' => 'reports',
        'action' => 'financial_day_begin'
    ),
    'type' => 'get'
));

Upvotes: 2

Related Questions