cakephp 2 ajax form

前端 未结 2 1727
生来不讨喜
生来不讨喜 2020-12-19 14:33

I\'m having trouble building an ajax form in cakephp 2 which obviously has changed a lot since 1.3.

I\'m using the following code:

2条回答
  •  粉色の甜心
    2020-12-19 15:17

    Try this in your view file:

    Js->get('#CommentSaveForm')->serializeForm(array('isForm' => true, 'inline' => true));
        $this->Js->get('#CommentSaveForm')->event(
              'submit',
              $this->Js->request(
                array('action' => 'save'),
                array(
                        'update' => '#commentStatus',
                        'data' => $data,
                        'async' => true,    
                        'dataExpression'=>true,
                        'method' => 'POST'
                    )
                )
            );
        echo $this->Form->create('Comment', array('action' => 'save', 'default' => false));
        echo $this->Form->input('Comment.comments_name');
        echo $this->Form->input('Comment.comments_email');
        echo $this->Form->input('Comment.comments_text');
        echo $this->Form->end(__('Submit'));
        echo $this->Js->writeBuffer();
    
    ?>
    

    NOTE: #CommentSaveForm is ID generated by CakePHP, If you have your own then use that

提交回复
热议问题