I want to provide additional server-side validation of the address forms in Magento, both in Checkout and Customer. I can override Mage_Checkout_OnepageController, Mage_Checkout_MultishippingController and Mage_Customer_AddressController, but that seems a bit much, and I would have to explicitly include the controller path, which seems dirty.

If I rely on the events system and do my validation after the appropriate controller action I might have to actively undo things done by the controller, such as remove session messages or delete or change addresses in the session. (I'd also be relying on the events system being synchronous, which while true seems dirty, and I'd be relying on the order of events if other events affect what I'm working on.)

I suppose the best bet would be to override Mage_Eav_Model_Form->validateData(). The only problem with that unlike some of the above options it only gives me the opportunity to set error messages, and sometimes you want to modify the actual JSON data going back (for example, to give the user the ability to choose among alternatives).

When I researched how to do this Google turned up results about overriding client-side validation, but there doesn't seem to be much about server-side. Is there a generic right way to do server-side form validation overrides?

Update: I also discovered there is a callback registry for Varien_Object->save(), but it only happens after the save. If there were a callback that happens before the save it would serve, but I didn't see anything like that.

1 Answer 1


One way will be to hook into controllers pre dispatch events and validate there, if you find something that is absolutely wrong, set action to be dispatched and redirect back to form page. It is still dirty way to do things, but when validation logic happens in controller, you have only few options.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.