Jump to content

[Free module] Customer form address and phone number validation for PrestaShop 8+


Daresh

Recommended Posts

Hi!

Here is a simple module that will allow you to apply additional validation to customer address fields.

image.png.16a7c1fdc05d6f1b9c980773ce385870.png

In the first version it works like this:
1. You can validate the phone number using the libphonenumber library. It's a code based on how Google validates phone numbers on Android system, so quite a fancy tool. It works this way:
 - if the phone number has a country prefix (+XX), it is validated according to the rules for prefixed country
 - if the phone number does not have a country prefix, it is validated according to rules for the selected country in the form

2. You can validate the address1 field using a given (configurable) regular expression. The default one is actually quite simple and all it does is assuring that the address contains at least two letters and a number anywhere. It's mainly to make sure your customers will not omit home number in the address. Of course it's not perfect, but address validation is a hard task, that's why you can always customize the regular expression to your needs.

The module supports PrestaShop 8+ mainly because I am using the "lite" version of the libphonenumber library, which is quite new and requires PHP 8 to run.

After installing the module, you can adjust the error messages using the standard PrestaShop translation panel.

Looking forward to your comments and tests! 🙂

gmadmitter_1_0_0.zipFetching info...

 

  • Like 2
  • Thanks 1
Link to comment
Share on other sites

  • 1 month later...

Nie działa mi nie da się zainstalować w Prestaschop :

 

w klasach/ ConfigurationTest.php (linia 252)

            return false;

        }

        closedir($dh);

        $dummy = rtrim($dir, '\\/') . DIRECTORY_SEPARATOR . uniqid();

        if (@file_put_contents($dummy, 'test')) {

            @unlink($dummy);

            if (!$recursive) {

                return true;

            }

        } elseif (!is_writable($dir)) {

Link to comment
Share on other sites

  • 6 months later...
  • 4 weeks later...
  • 1 month later...

Cześć Daresh,

I'm trying to run this module on PrestaShop 8.2.0 (PHP 8.1.31) but without debug mode it's throwing me following error. If I'm in debug mode the module is working fine. I'm also using JPresta Cache plugin if it's important.

[02-Jan-2025 11:27:55 Europe/Warsaw] PHP Fatal error:  Uncaught Error: Class "libphonenumber\PhoneNumberUtil" not found in /home/xxx/modules/gmadmitter/gmadmitter.php:171
Stack trace:
#0 /home/xxx/modules/pagecache/pagecache.php(3681): GmAdmitter->hookActionValidateCustomerAddressForm()
#1 /home/xxx/override/classes/Hook.php(24): PageCache::execHook()
#2 /home/xxx/classes/Hook.php(418): Hook::coreCallHook()
#3 /home/xxx/classes/Hook.php(983): HookCore::callHookOn()
#4 /home/xxx/classes/form/CustomerAddressForm.php(140): HookCore::exec()
#5 /home/xxx/classes/form/CustomerAddressForm.php(149): CustomerAddressFormCore->validate()
#6 /home/xxx/classes/checkout/CheckoutAddressesStep.php(95): CustomerAddressFormCore->submit()
#7 /home/xxx/classes/checkout/CheckoutProcess.php(76): CheckoutAddressesStepCore->handleRequest()
#8 /home/xxx/controllers/front/OrderController.php(252): CheckoutProcessCore->handleRequest()
#9 /home/xxx/classes/controller/Controller.php(319): OrderControllerCore->initContent()
#10 /home/xxx/classes/Dispatcher.php(510): ControllerCore->run()
#11 /home/xxx/index.php(39): DispatcherCore->dispatch()
#12 {main}
  thrown in /home/xxx/modules/gmadmitter/gmadmitter.php on line 171

 

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...