On Fri, May 29, 2009 at 10:52 AM, [email protected]
<[email protected]> wrote:
>
>
> I keep getting the following message, after I have clicked 'add' on my
> form, when it is invalid in any way and when a submission is
> successful:
>
> Not Found
> Error: The requested address '/contacts/add' was not found on this
> server.
Set debug to 2 in core.php. Cake defaults to a 404 when there's an
error and debug is at 0.
> On a successful submission the e-mail is sent, but it still results in
> the above message. I have added a redirect to my controller to
> redirect back to the page, but no error messages are displayed
> accordingly. I have added $form->error('Contact.name').. etc but they
> do not display the messages defined in my model.
> I do not have a view file for the controllers action and I just want
> to call the method then go back to the initial page and display the
> appropriate error messages.
I don't see a redirect in your method. In any case, you want to avoid
doing that because your $validationErrors won't exist if you redirect.
The correct way to handle this is to only redirect when the save is
successful. That way, Cake will redisplay the form otherwise, and
FormHelper will know to display the error messages.
Think of it this way: When the user first browses to /contacts/add
Cake will display the add view, which contains a form. Your save code
will not be parsed because $this->data is empty (or, in your case,
because RequestHandler->isPost() returns false). FormHelper will
create the empty form.
When the form is submitted, RequestHandler->isPost() retrn true and
Cake will run through your save() operations. If that is successful,
your code should redirect somewhere else.
If the save fails, though, your code shouldbe allowed to finish
running therough the controller method. Cake will, in turn, re-display
the form. Because your $validationErrors is not empty, FormHelper
should display the error messages.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---