[TYPO3-mvc] ajax and validation

Helmut Hummel helmut.hummel at typo3.org
Thu Nov 27 18:53:24 CET 2014


Hi Christian,

On 27.11.14 11:04, Christian Kartnig wrote:
> Hi!
>
> The view is not the problem, the problem is to detect the validation
> errors within the action (is this possible within initializeAction?)

initializeAction is too early as validation has not yet taken place

> and
> to send appropriate Error messages via json.
>
> Of course I could create a view, where only the validation Errors are
> displayed and extract the errors using jQuery, but I was looking for a
> cleaner solution.

The cleanest solution is to overload the errorAction in your controller.
This method will be called if validation fails. You have access there to 
all validation errors and can return a json.

To not break "normal" error handling, you need to identify if the 
current request is an Ajax request (e.g. by looking at a special 
argument that will be sent with your Ajax call), do what you need to do 
and otherwise call the parent method.

HTH

Kind regards,
Helmut

-- 
Helmut Hummel
Release Manager TYPO3 6.0
TYPO3 CMS Active Contributor, TYPO3 Security Team Member

TYPO3 .... inspiring people to share!
Get involved: typo3.org


More information about the TYPO3-project-typo3v4mvc mailing list