erserpico Posted April 19, 2023 Share Posted April 19, 2023 is possible? Link to comment Share on other sites More sharing options...
AddWeb Solution Posted April 20, 2023 Share Posted April 20, 2023 Hi @erserpico, Quote Make the VAT field mandatory if the Company field is filled in PrestaShop 1.7.8.8. Goto controllers/front/AddressController.php file and find the postProcess() function which is responsible for handling the form submission and validation. Modify the validation rules to check if the Company field is filled, and if it is, require the VAT field to also be filled. The code should be something like, if (Tools::isSubmit('submitAddress')) { $company = Tools::getValue('company'); $vat_number = Tools::getValue('vat_number'); if (!empty($company) && empty($vat_number)) { $this->errors[] = $this->module->l('Please enter a valid VAT number'); } elseif ($vat_number && !Tools::isVAT($vat_number)) { $this->errors[] = $this->module->l('Invalid VAT number'); } } Link to comment Share on other sites More sharing options...
erserpico Posted April 20, 2023 Author Share Posted April 20, 2023 49 minuti fa, AddWeb Solution dice: Hi @erserpico, Goto controllers/front/AddressController.php file and find the postProcess() function which is responsible for handling the form submission and validation. Modify the validation rules to check if the Company field is filled, and if it is, require the VAT field to also be filled. The code should be something like, if (Tools::isSubmit('submitAddress')) { $company = Tools::getValue('company'); $vat_number = Tools::getValue('vat_number'); if (!empty($company) && empty($vat_number)) { $this->errors[] = $this->module->l('Please enter a valid VAT number'); } elseif ($vat_number && !Tools::isVAT($vat_number)) { $this->errors[] = $this->module->l('Invalid VAT number'); } } thank you. I tried, but it completely ignores. Link to comment Share on other sites More sharing options...
AddWeb Solution Posted April 20, 2023 Share Posted April 20, 2023 18 minutes ago, erserpico said: thank you. I tried, but it completely ignores. Okay, Do you have any custom module? Link to comment Share on other sites More sharing options...
erserpico Posted April 20, 2023 Author Share Posted April 20, 2023 48 minuti fa, AddWeb Solution dice: Okay, Do you have any custom module? yes I have a form that just adds a field to the classic form Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now