• Resolved mehdismekouar

    (@mehdismekouar)


    Hi!

    First congratulations for this wonderful plugin. I am using the phone field with international validation and it works fine except for numbers that start with 5 or 7 after +212

    For example:
    This works +212611223344
    Theses does not work even if they are valid moroccan numbers
    +212711223344
    +212511223344

    Please help

Viewing 14 replies - 1 through 14 (of 14 total)
  • Plugin Support Jair – WPMU DEV Support

    (@wpmudevsupport15)

    Hi @mehdismekouar,

    I hope you are doing well today!

    Thank you for bringing this to our attention. I was able to confirm the issue and informed our Forminator team accordingly. so that they can dig into this further. Hopefully, very soon the issue will be fixed and an update will be released.

    Thank you for your patience while we look into this further.

    Kind regards,
    Zafer

    Thread Starter mehdismekouar

    (@mehdismekouar)

    Thank you. looking forward to it

    Plugin Support Kris – WPMU DEV Support

    (@wpmudevsupport13)

    Hi @mehdismekouar

    As said above, this was already forwarded to our developers and I am marking this thread as resolved, but if you have any additional questions feel free to let us know.

    Kind Regards,
    Kris

    Thread Starter mehdismekouar

    (@mehdismekouar)

    Yes, by the way also the number 8 after +212 is a valid moroccan number, thanks

    Thread Starter mehdismekouar

    (@mehdismekouar)

    Any news guys? i think there were an update to forminator since but the problem is still there

    Plugin Support Williams – WPMU DEV Support

    (@wpmudev-support8)

    Hi @mehdismekouar

    I don’t have any news on that yet, I’m afraid. There are a lot of active tasks that our developers are dealing with – new features and improvements, bug fixes and so on – and not all of them can be addressed “in one go”.

    I apologize for keeping you waiting but I’m afraid I don’t have an ETA on this.

    Please keep an eye on the plugin changelog here:

    https://www.ads-software.com/plugins/forminator/#developers

    Kind regards,
    Adam

    Thread Starter mehdismekouar

    (@mehdismekouar)

    Guys!

    3 months and the problem still persists, we’re losing clients unfortunately and we’re seriously thinking about switching from forminator because of that problem

    Any workaround to solve the problem before an official update fix please?

    Plugin Support Dmytro – WPMU DEV Support

    (@wpmudevsupport16)

    Hello @mehdismekouar,

    Please take our apologies for the delay.

    We are checking with the Second Line Support if there’s any workaround (such as a must use plugin). Please note, that it may take longer for us to reply, depending on the current amount of complex tasks.

    Once there’s feedback from the SLS techs, we will be updating you ASAP.

    Best Regards,
    Dmytro

    Plugin Support Dmytro – WPMU DEV Support

    (@wpmudevsupport16)

    Hello @mehdismekouar,

    Could you please try adding the following snippet as a must use plugin:

    <?php
    
    add_filter( 'forminator_field_phone_validation_rules', 'forminator_allow_moroccan_phone_numbers', 10, 4 );
    
    function forminator_allow_moroccan_phone_numbers( $rules, $field_id, $field, $form_id ) {
        if ( strpos( $rules, 'forminatorPhoneInternational' ) !== false ) {
            $rules .= '"forminatorPhoneMorocco": true,';
        }
        return $rules;
    }
    
    add_action( 'wp_footer', 'forminator_moroccan_phone_fix' );
    
    function forminator_moroccan_phone_fix() {
        ?>
        <script>
        (function($) {
            $(document).ready(function() {
                if (typeof $.validator !== 'undefined') {
                    $.validator.addMethod("forminatorPhoneMorocco", function(value, element) {
                        return this.optional(element) || /^\+212[5785]\d{8}$/.test(value);
                    }, "Please enter a valid Moroccan phone number starting with +2125, +2127, or +2128");
                }
            });
        })(jQuery);
        </script>
        <?php
    } 

    – copy and paste the code in a text editor, and save it as a PHP file, for example forminator-phone-validation.php

    Upload the saved file to /wp-content/mu-plugins/ directory on the server, refresh the page with your form, and test it again.

    Hope this helps. Let us know if there’s still any issue.

    Best Regards,
    Dmytro

    Thread Starter mehdismekouar

    (@mehdismekouar)

    Great! Thanks for the code

    Unfortunately another problem emerged, not because of the code you provided but since last updates, the phone field allows to have “0” between the country code and the actual number, which he didn’t allow before rightfuly

    It allows it now for all country numbers and it’s not correct

    For example this is a french number: +33 7 68 56 32 32
    I can type +33 0 7 68 56 32 32 and it considers it as correct which is not

    That problem prevents us from having the correct phone numbers for calling which is another huge block

    Please provide some workaround for that too

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @mehdismekouar,

    I have brought the mentioned behavior to the notice of the Forminator developers for further review. We’ll update you here once we have more feedback on this as soon as possible.

    Kind Regards,
    Nebu John

    Plugin Support Nebu John – WPMU DEV Support

    (@wpmudevsupport14)

    Hi @mehdismekouar,

    The following workaround could help to fix the issue with French mobile numbers.

    <?php
    function wpmudev_phone_field_france_fix() {
        global $post;
        if ( is_a( $post, 'WP_Post' ) && ! has_shortcode( $post->post_content, 'forminator_form' ) ) {
            return;
        }
        ?>
        <script type='text/javascript'>
        jQuery(document).ready(function($) {
            setTimeout(function() {
    			$('.forminator-custom-form').trigger('after.load.forminator');
            }, 100);
    
            $(document).on('after.load.forminator', function(e, form_id) {
                if ( e.target.id == 'forminator-module-1609' ) { // Please change the form ID.
                    $('#phone-1 input').on('change input', function(){
                        var dial_code = $(this).intlTelInput( 'getSelectedCountryData' ).dialCode, country_code = '+' + dial_code;
                        var phone_number = $(this).val().replace(country_code, '');
                        if ( phone_number.charAt(1) == 0 ) {
                            phone_number = phone_number.replace(phone_number.charAt(1), '');
                            $(this).val(country_code+phone_number);
                        }
                    });
                }
            });
        });
        </script>
        <?php
    }
    add_action( 'wp_footer', 'wpmudev_phone_field_france_fix', 9999 );

    Kindly note that you must update the form ID and mobile field ID according to your specific form in the provided code above. The code could be added using a mu-plugin, I hope the following guide comes in handy: https://wpmudev.com/docs/using-wordpress/installing-wordpress-plugins/#create-an-mu-plugin-directory

    Please feel free to get back to us if you need any further clarification.

    Kind Regards,
    Nebu John

    Thread Starter mehdismekouar

    (@mehdismekouar)

    The french number i gave was just an example

    The 0 problem shows up on all country numbers

    Will this code work with all country numbers or just with french?

    Plugin Support Nithin – WPMU DEV Support

    (@wpmudevsupport11)

    Hi @mehdismekouar,

    This should work with all numbers when tested, in case you still face issues, please do share an example number in the next reply too.

    For the snippet to work, you’ll have to make sure “Load form using AJAX” is disabled in the form settings under the “Behavior” tab > Rendering

    Please do let us know how that goes.

    Kind Regards,

    Nithin

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘moroccan phone validation’ is closed to new replies.