Forms are submitted via ajax in exactly the same way they might be without CakePHP. If it's me, Here's what I'd do...
In my view:
<?php echo $this->Html->script(
array( 'vendors/jquery.min', 'customjs' )
, array( 'inline' => false, 'once' => true )
) ?>
<?php echo $this->Form->create( ... ) ?>
... your form content here ...
<?php echo $this->Form->end( 'Share' ) ?>
In a custom Javascript file (/js/custom.js
):
$(function() {
$('#your-form' ).submit( function() {
// make your ajax call
$.post( ... );
return false; // prevent a new request
});
});
Finally, create a new controller and/or action to handle the URL being requested by your ajax call. Those are just the highlights, of course, but they illustrate the key distribution of concerns:
- Include the necessary JS files so your view has access to them.
- Attach the submit event handler on document.ready (not inline)
- Prevent the form from performing its regularly scheduled submit after the ajax call by returning false from the event handler.
Hope that helps.