/cakephp-jquery-ajax-forms

Ajax forms for CakePHP made easy with a cake plugin and the JQuery form plugin

Primary LanguageJavaScript

What is this?

This is a CakePHP component and JQuery plugin to enable you to quickly ajaxify simple CakePHP forms. I've found it a ballache to do this myself every time, so this generifies it a bit.

How do I use it?

- Put the ajax_forms.php component in your components/ directory
- Put the jquery.cake.form.js file into your webroot/js/ directory
- If you have a normal form that's working, and you want to ajaxify it, do the following:
  - add AjaxForms to your controller's components, and add jquery.form.js to your view.
  - in your javascript, do something like...
        $('#myform').cakeAjaxForm();

How does it work?

The jQuery plugin uses the jQuery.form to post off the form. If it gets back any errors, it adds a div with the error-messae class in the relevant place.
The component checks if the request is both POST and AJAX. If it is, it overrides the rendering - it takes all the models in the $this->data array, and sends back any invalid fields (you should have tried to validate this in your action) as JSON.