function onValidateSavedForm(Am_Event $e) { if (!$this->getConfig('tax_location_validate_self')) { return; } $form = $e->getForm(); $el = $form->getElementById('f_country'); if (!empty($el)) { $user_country = $el->getValue(); try { // Form has country element. Now we need to check user's choice and validate it agains IP country. $current_country = $this->getDi()->countryLookup->getCountryCodeByIp($this->getDi()->request->getClientIp()); } catch (Exception $e) { // Nothing to do; $error = $e->getMessage(); } if (empty($current_country) || $current_country !== $user_country) { // Need to add self-validation element; if (!($sve = $form->getElementById('tax_self_validation')) || !$sve->getValue()) { $sve = new Am_Form_Element_AdvCheckbox('tax_self_validation'); $sve->setLabel(array(___('Confirm Billing Country')))->setId('tax_self_validation')->setContent(sprintf("<span class='error' style='display:inline;'><b>" . ___("I confirm I'm based in %s") . "</b></span>", $this->getDi()->countryTable->getTitleByCode($user_country))); foreach ($form as $el1) { $form->insertBefore($sve, $el1); break; } if ($sve->getValue()) { // Confirmed; $this->getDi()->session->tax_self_validation_country = $el->getValue(); } else { $form->setError(___("Please confirm your billing address manually") . "<br/>" . ___("It looks like you are not at home right now.") . "<br/>" . ___("In order to comply with EU VAT Rules we need you to confirm your billing country.")); } } else { // Element already added; nothing to do } } } }