php - HTML Form in CakePHP -
i don't want use formhelper cakephp, because want use ajax in app. how can pass data form controller? i'm using $.post
jquery error. thanks!
you can use ajax cakephp form helper.
in view file .ctp put:
echo $this->form->create('model', array('id'=>'yourformid', array('default'=>false))); echo $this->form->input('field'); echo $this->form->submit('save'); echo $this->form-->end
notice in form->create passing default=>false tells form not normal "submit".
at bottom of view file .ctp put:
$data = $this->js->get('#yourformid')->serializeform(array('isform' => true, 'inline' => true)); $this->js->get('#yourformid')->event( 'submit', $this->js->request( array('action' => 'youraction', 'controller' => 'yourcontroller'), array( 'update' => '#flash', 'data' => $data, 'async' => true, 'dataexpression'=>true, 'method' => 'post' ) ) ); echo $this->js->writebuffer();
the above cakephp js helper write ajax , javascript php. grabs form data being submitted , serializes , passed /yourcontroller/youraction via ajax. update=>#flash telling cake update #flash div after action done.
remember in controller have public
public $helpers = array('js'); public $components = array('requesthandler');
Comments
Post a Comment