0
votes

I'm trying to just do some simple user input using jquery loaded views. In this example, I have a simple button on a web page that sends an ajax request to load a view containing a form into a div, which works fine. When the form submits, the data does not get decoded and added to the request data array.

Here is a snippet of the code from the main page with the simple link

    <?php 
    $this->Js->get('#sayHi')->event(
        'click',
        $this->Js->request(
            array('action' => 'sayHi'),
            array('update' => '#sayHiOutput')
        )
    );
    ?>
    <li><?php echo $this->Form->button(__('Say Hi'),array(
        'id'=>'sayHi',
        'href'=>$this->Html->url(array('action'=>'sayHi')),
        )); 
    ?></li>
    <li><div id=sayHiOutput></div></li>

That loads the view into the div. The view is like this:

          <?php
            $data = $this->Js->get('#WidgetSayByeForm')->serializeForm(array('isForm' => true, 'inline' => true));
            $this->Js->get('#WidgetSayByeForm')->event(
              'submit',
              $this->Js->request(
                array('action' => 'sayBye'),
                array(
                        'update' => '#sayHiOutput',
                        'data' => $data,
                        'async' => true,    
                        'dataExpression'=>true,
                    )
                )
            );
          ?>
          <?php echo $this->Form->create('Widget',array('action'=>'sayBye','default'=>false));?>
            <fieldset>
                <legend><?php echo __('Add Widget'); ?></legend>
            <?php
                echo $this->Form->input('name');
            ?>
            </fieldset>
          <?php echo $this->Form->end(__('Submit'));?>
          <?php echo $this->Js->writeBuffer(); ?>

This code triggers an ajax request when the form is submitted and serializes the data for the request. Everything appears to work correctly as I have checked the xml request data using TamperData. However in the controller action 'sayBye', the request data array is empty, although the 'query' array shows the right information, here is what I printed into the log file:

[data] => Array
    (
    )

[query] => Array
    (
        [_method] => POST
        [data] => Array
            (
                [Widget] => Array
                    (
                        [name] => asdf
                    )

            )

    )

What I was expecting was to see the data array have the same contents as the subarray shown in the query data. So I'm guessing this is another case where I'm just missing something obvious but I haven't been able to figure it out. Maybe the hidden _method should not be POST? Any help would be appreciated, thanks.

Matt

1

1 Answers

2
votes

You need to pass the 'type' => 'POST' option to the request() method