Found the problem.

Will explain it here to help those who come after...

The problem arose because the form was submitting to the Pages
controller, which was doing a requestAction() to the Subproducts
Controller, which was doing the validation. Thus, all the validation
information was in the context space of the Subproducts controller.
That's why when I went in and debugged, I saw all the validation error
flags set - I was debugging within the context space of the Subproducts
controller.

However, when control flow returned to the Pages Controller after the
requestAction() completed, the Pages controller had no knowledge of the
validation the Subproducts controller performed. So, when it rendered
the view and $html->tagErroMsg() tried to check if there are any
errors, it didn't see any (even though it is looking at the same model
'Product' and field 'name') because the errors are not visible in the
context space of the Pages Controller, and the view helper runs in the
context space of the controller to which it belongs.

I fixed the problem by doing the validation in the pages controller
before the requestAction to the Subproducts controller, and if
validation failed, I just returned without continuing with the
requestAction.

Validation errors are appearing in the search form nicely now, just as
you would expect.

Short Moral of the story:

- Controllers have different contexts.
- A validation performed in one is not seen by another.
- When you do a requestAction(), you are no longer running in the same
context as the first controller, you are transferred to a new context,
so validation errors set are not seen in the original controller, and
when you return from the requestAction, the validation info is lost as
is the context in which they were created.

Hope this helps somebody. Took me hours.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" 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
-~----------~----~----~----~------~----~------~--~---

Reply via email to