Magento – Catch and verify custom parameters at registration

customerevent-observermagento-1server-setupvalidation

i've added some attributes for each user on my Magento installation.
Each attribute is correctly showed in the registration fields, user can fill them, they're mandatory and they are also validated by Magento's javascript validation (followed the tutorial here : http://inchoo.net/magento/programming-magento/validate-your-input-magento-style/)

I need to validate also server side, i started creating a module following a tutorial online.

Every example that i've found overrided Magento's standard attributes.
What should i override to validate my custom attributes?
Which event should i catch?
I'm a bit confused…

UPDATE : here is a zip file of my module https://www.dropbox.com/s/7nxjx6mh0hly6yn/MyModule.zip?dl=0. Let me know if you spot the error.

Best Answer

The validate() method of Mage_Customer_Model_Customer is called at multiple occations which are all not influencable with observers. Unfortunately the method itself hard-wires quite a few things, so if you want to change or extend customer validation, the most reliable way is to rewrite the customer model and override validate().

public function validate()
{
    $errors = parent::validate();
    if ($errors = true) { // means: "no errors" - don't ask!
        $errors = array();
    }
    if (!my_custom_validation($this->getMyCustomAttribute()) {
        $errors[] = "That's invalid!";
    }
    if (empty($errors)) {
        return true;
    }
    return $errors;
}
Related Topic