user1469634
user1469634

Reputation: 13

CakePHP 2.0+: Retrieving POST data from Js->submit form in controller

I am using $this->Js->submit to pass a value to my controller asynchronously and than update a div (id = #upcoming). Somehow I cannot save/retrieve the value of the field 'test' which is passed to my controller. Firebug tells me that the correct value is passed. What am I doing wrong?

View file (playlist.ctp):

echo $this->Form->create('Add', array('url' => array('controller' => 'Gods', 'action' => 'add')));
echo $this->Form->input('test');       
echo $this->Js->submit('Addddd', array(
'url' => array(
    'controller' => 'Gods',
    'action' => 'add'
),
'update' => '#upcoming'
));
echo $this->Form->end();

echo $this->Js->writeBuffer(array('inline' => 'true'));

Controller action:

public function add()
{
$this->autoLayout = false;
   $this->layout = 'ajax';
$link = $this->request->data['Add']['test'];
$this->set('test',$link);
}

And its view file (add.ctp):

<?php
echo $test;
?>

Thanks for your help!

Upvotes: 1

Views: 1207

Answers (1)

Jeroen
Jeroen

Reputation: 1638

have you tried pr($link) in the controller method? Or just send it to a log file if you prefer that. That way you can see if the data is received.

If so, I think there is nothing returned because of

 $this->autoLayout = false;

Try it without this. It will still call the ajax layout instead of the default. Otherwise you have to manualy call the render function

$this->render('add');

EDIT As explained in the comments below, make sure your views are in the right place. (that would be the view folder associated with the controller)

Upvotes: 1

Related Questions