Sunday, February 27, 2011

Re: CakePHP form validation before sending post to the requested controller function

Sorry, you are absolutely right, redirecting causes the validation
error messages to be lost. So, reverse the logic.

You currently have a view that renders the form that collects the
search criteria (you don't say what this is but I'll call it
search_form as I did above). So there is an action and a view called
search_form. The action search_form() will do the call to validates()
and if the result is false, re-renders the search form with the
errors. If the validation is successful, THEN you redirect to the
action/view that renders the search results.

function search_form() {
if ($this->Plan->validates()) {
$this->redirect('search'); // Renders the search results
}
// Drops through to re-render search form
}

Ken

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php

No comments: