Rien
Rien

Reputation: 143

Send data to controller with js helper

I'm trying to send some data to my controller with the Js helper like so:

view:

<?php   
$this->Js->get('#FieldId')->event( //fieldId is a selectbox
    'change',
    $js->request(
        array(
            'controller'=>'users',
            'action'=>'check'
        ),
        array(
            'update'=>'#result',
            'data'=>'what should I put in here?'
        )
    )
);
?>

What should I put in data to send the value of the selected item of #fieldId and how can I us this data in my controller. The CakePHP documentation 'book' doesn't really explain much, and I'm not an expert either...

Upvotes: 0

Views: 935

Answers (2)

suresh sunkari
suresh sunkari

Reputation: 11

I think this will help you.

<?php 

   $this->Js->get('#FieldId')->event('change', $this->Js->request(array(
           'controller' => 'users',
           'action' => 'check/DataName(view name)'
               ), array(
           'update' => '#result',
           'async' => true,
           'method' => 'post',
           'dataExpression' => true,
           'data' => $this->Js->serializeForm(array(
               'isForm' => true,
               'inline' => true,
           )),
       )) );
   ?>

Upvotes: 0

kuba
kuba

Reputation: 21

I found out that additional variables should be passed in that manner:

'data' => 'variableName=value'

So in the controller there is:

$this->params['form']['variableName']

There is also the possibility to eval some javascript values in 'data' but you have to set 'dataExpression' to true in the option array before.

Upvotes: 2

Related Questions