Jump to content

Make the VAT field mandatory if the Company field is filled in PrestaShop 1.7.8.8


erserpico

Recommended Posts

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...