fixed phone number validation error on opc page

This commit is contained in:
Shreesh Arora
2024-08-05 20:28:34 +05:30
parent 3aac5a530b
commit 4c31e2a86d
5 changed files with 19 additions and 1 deletions

View File

@@ -1159,8 +1159,12 @@ class AdminCustomersControllerCore extends AdminController
$this->errors[] = Tools::displayError('Phone number is required.');
}
}
$className = 'CartCustomerGuestDetail';
$rules = call_user_func(array($className, 'getValidationRules'), $className);
if ($phone && !Validate::isPhoneNumber($phone)) {
$this->errors[] = Tools::displayError('Invaid phone number.');
} elseif ($phone && Tools::strlen($phone) > $rules['size']['phone']) {
$this->errors[] = Tools::displayError('Invaid phone number.');
}

View File

@@ -427,14 +427,20 @@ class AuthControllerCore extends FrontController
}
}
$className = 'CartCustomerGuestDetail';
$rules = call_user_func(array($className, 'getValidationRules'), $className);
if ($error_phone) {
$this->errors[] = Tools::displayError('Phone number is required.');
} else {
if (Tools::getValue('phone') && !Validate::isPhoneNumber(Tools::getValue('phone'))) {
$this->errors[] = Tools::displayError('Invald phone number.');
} elseif (Tools::getValue('phone') && Tools::strlen(Tools::getValue('phone')) > $rules['size']['phone']) {
$this->errors[] = Tools::displayError('Invald phone number.');
}
if (Tools::getValue('phone_mobile') && !Validate::isPhoneNumber(Tools::getValue('phone_mobile'))) {
$this->errors[] = Tools::displayError('Invald mobile phone number.');
} elseif (Tools::getValue('phone_mobile') && Tools::strlen(Tools::getValue('phone_mobile')) > $rules['size']['phone']) {
$this->errors[] = Tools::displayError('Invald mobile phone number.');
}
}

View File

@@ -88,8 +88,12 @@ class IdentityControllerCore extends FrontController
$this->errors[] = Tools::displayError('Phone number is required.');
}
}
$className = 'CartCustomerGuestDetail';
$rules = call_user_func(array($className, 'getValidationRules'), $className);
if ($phone && !Validate::isPhoneNumber($phone)) {
$this->errors[] = Tools::displayError('Invaid phone number.');
} elseif ($phone && Tools::strlen($phone) > $rules['size']['phone']) {
$this->errors[] = Tools::displayError('Invaid phone number.');
}
if (!count($this->errors)) {

View File

@@ -119,8 +119,12 @@ class OrderOpcControllerCore extends ParentOrderController
if (Configuration::get('PS_ONE_PHONE_AT_LEAST') && !$phone) {
$this->errors[] = Tools::displayError('Phone number is a required field.', false);
}
$className = 'CartCustomerGuestDetail';
$rules = call_user_func(array($className, 'getValidationRules'), $className);
if (!Validate::isPhoneNumber($phone)) {
$this->errors[] = Tools::displayError('Please enter a valid Mobile phone number.', false);
} elseif (Tools::strlen($phone) > $rules['size']['phone']) {
$this->errors[] = Tools::displayError('Please enter a valid Mobile phone number.', false);
}
$_POST['lastname'] = $_POST['customer_lastname'];

View File

@@ -86,7 +86,7 @@
<div class="row">
<div class="{if isset($one_phone_at_least) && $one_phone_at_least}required {/if}form-group col-sm-6">
<label for="phone">{l s='Phone'}{if isset($one_phone_at_least) && $one_phone_at_least} <sup>**</sup>{/if}</label>
<label for="phone">{l s='Phone Number'}{if isset($one_phone_at_least) && $one_phone_at_least} <sup>**</sup>{/if}</label>
<input type="text" class="text form-control validate" name="phone" id="phone" data-validate="isPhoneNumber" value="{if isset($guestInformations) && isset($guestInformations.phone) && $guestInformations.phone}{$guestInformations.phone}{/if}" />
</div>
</div>