Form validation with Ajax

Published on and tagged with ajax  documentation  tip  tutorial

I have started an FAQ article in the CakePHP Wiki about form validation with Ajax. With a simple example I show how to display messages depending on the text you enter, and how to submit your form only when all input fields are filled out correctly. Feedback is welcome!

4 comments baked

  • cyberlogi

    Hey, I copied your post (almost exaclty). It looks like it could work great, except that everytime the function ajaxValidateUsername is called in the controller, it causes my default layout to render inside the div instead of just labelText. I’ve added $this->layout = “ajax”; but it doesn’t do any good. Any ideas what i need to change in order to get it to just print the message in labelText?


  • cakebaker

    Hm, have you tried $this->render(‘viewname’, ‘ajax’); ? Or the RequestHandler component: $this->RequestHandler->setAjax($this);


  • Arvind Thakur

    hi as the wiki has been removed where is the information now.. as this article..

  • cakebaker

    @Arvind Thakur: You can find at least some information in the bakery ( or in the manual ( And the content of the wiki is probably still available via Google’s cache. HTH

© daniel hofstetter. Licensed under a Creative Commons License