0

I have a form element that has an onchange listener to trigger an update another element via ajax.

However, I want the ajax post data to include two form elements, not just the one that is in shown below ($data).

I have tried to put the two elements I want to serialize in their own nested form, which does post the values of both elements, but because this new form is nested in the main page form cakephp then ignores these elements when submitting the main page form.

$data = $this->Js->get('#Reviewevent'.$index.'score')->serializeForm(array(
    'isForm' => true,
    'inline' => true
));

$this->Js->get('#Reviewevent'.$index.'score')->event('change', $this->Js->request(array(
    'controller'=>'events',
    'action'=>'getEventDescription'
    ), 
    array(
        'update'=>'#'.$index.'Description',
        'async' => true,
        'method' => 'post',
        'dataExpression'=> true , 
        'data'=> $data
    )
));

1 Answer 1

1

Turns out you can serialise a div with jquery, you don't need it to be a form. I just put the two elements I wanted to send in the ajax request in a div instead of a nested form and it worked fine.

 $data = $this->Js->get('#'.$index.'ThisDivHasTwoFormElementsInIt')->serializeForm(array(
    'isForm' => true,
    'inline' => true
));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.