Question

I'm having a website http://1008designs.in/ There in the home page I have built a Enquiry Form, The form usual validation works fine, but I need Jquery & Ajax validation, the form submits to 'enquiry/add', Pls help me on how to use Jquery Ajax in cakephp 2.0, I gone through a video of Andrew Perkins, but It didn't work for me. If I submit the form, then the whole home page is displayed on that Enquiry Div. I'm trying it from a week, but not working, pls help me as soon as possible.

Was it helpful?

Solution

When you submit form with ajax to controller enquiry/add the html returend by ajax request is a view associated with this enquiry/add. If you want to customize this html you have to modify add action in controller:

At the end of the action try this:

if($this->request->is('ajax'))
{
    $this->autoRender = false;
    $this->render('/elements/enquiry_success');
}

And in app/view/elements/ add enquiry_success.ctp containing some html/php code which will be returned to #succces div (for example <p>Enquiry added!!!</p>).

This code detects if request is ajax and id it is it doesnt render default view for action but some element.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top