Follow the instructions here to add ajax support to your cake project.
Then enable the ajax helper in the controller, which will display your view:
$this->helpers('Ajax');
You should be able to display your link like this and it will not direct the user to the search page:
<?php echo $this->Ajax->link( '+', array('action' => 'add_data', $reference_id), array('update' => 'my-div') ); ?> <div id='my-div'></div>
Since you want the user to be able to submit data to this action, you might want to view the placement of the form instead of a simple link. Ajax Helper also provides the ability to submit a form through Ajax:
echo $form->create(); echo $form->input('field1'); echo $form->input('field2'); echo $ajax->submit('Submit', array( 'url'=> array('controller'=>'mycontroller', 'action'=>'add_data'), 'update' => 'my-div' )); echo $form->end();
In your controller ....
function add_data() { // ... do something $this->layout = 'ajax'; $this->set('message', 'Your message here!'); }
In the add_data view ....
<?php echo $message; ?>
source share