[TYPO3-mvc] ajax and validation

Sebastian Schreiber me at schreibersebastian.de
Fri Nov 28 16:20:32 CET 2014


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Hi Christian,
in most cases, it depends on your used JS-Library, you can identify if
the current request is an AJAX request by checking it the following way:

if(!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
}


Of course would it be nice to have a dedicated method in the request
object of the mvc-framework e.g.

if($this->request->isXmlHttpRequest()) {
   //your ajax content goes here
}




Am 27.11.2014 um 18:53 schrieb Helmut Hummel:
> 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
> 


- -- 
Sebastian Schreiber
(Medieninformatiker B.Sc.)
(TYPO3 Certified Integrator)

Paul Nießen Straße 58
D-50969 Köln

T  0221 677 88 541
M  0176 431 05 790

Skype schreibersebastian.de

me at schreibersebastian.de
www.schreibersebastian.de

Steuernummer: 219 / 5302 / 3123
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (MingW32)

iQIcBAEBAgAGBQJUeJK/AAoJEA6Xt2+iF5N5iwAP/3H3IoXTPBt2VTZrq40SH4Kw
wHGynKGAJNdN1Btt5zj7TRmbdiSMrdAdcJDpcgkT3gATp3dX/bavyQw9/bK1d/OM
iDE6YXIepG4J0l6EctozpBWmzxsWlyK1dcDtgzy5ZNEAyD/2VzzYEMzpuVxCX43S
37A75ci9wpAYor64o7zw1nHrg2JCxaBAfYLtq7ywYEg7uQf/uJfAFdcW70PZ6wk+
EXmJihPGxur2hgc5lNrOpvI4g9xO0951s4PTfl/t9OM13vmr+OkmNyqr+T8qt42O
GjJk+AcQKOweRF8PZA7Q4fsGsit99dj8xjeZZmXt1eE6MEhHxsqUo8cqKLEwSxBF
eBbtzlu9i+Pa3waSt6BLxri3YoNCSY6K2HjDWJs//nBcSo83ekv1rECwp2SFIcow
1HPXBnmYkjvOUstk0vVgbBVbF379ECdv+RAnNYfLKiuIxQVmNBRq1WdHMuSOn8V9
VvyIy3I6wDZqPAMidfNxz0KS9Ji1voCQHxSlQsnLdOWCwYveDmmbQujwYbNDzAhd
VZ6QK8YTO0hF5U5tnbtLnFqCG8vy/eNotPYuZVsNA8eVU8cZm1lzj6QlY6+t44pH
u4MvzMcdOBDUCKwsdVZRJgrzi4zZ9MIjIn9Yg6IwcVsiIOSqBttHzMzJct/LGMYw
X7POyRSnS57Rbtmi2Xr6
=RQ6T
-----END PGP SIGNATURE-----


More information about the TYPO3-project-typo3v4mvc mailing list