• Resolved milesbonnier

    (@milesbonnier)


    When users subscribe/sign up using the form, they aren’t met with an error message, if they enter a false top-level domain (ex. hotmail.cim).

    Is it possible to manage which top-level domains are accepted etc. ?

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Contributor Freddie

    (@fmixell)

    Hey @milesbonnier,

    If you’re familiar with using Javascript you could add change listeners to your Easy Forms email inputs that double check which TLD is being used. In this example I’m only allowing .com .net and .co but you could add more if you’d like to support more.

    If you don’t know how to add custom Javascript you could use this plugin to do so https://www.ads-software.com/plugins/custom-css-js/

    (function() {
        const emailInputs = document.querySelectorAll( 'input[type=email]' );
        const submitButtons = document.querySelectorAll( '.yikes-easy-mc-submit-button' );
        
        emailInputs.forEach( function( singleInput ) {
            singleInput.addEventListener( 'change', handleChange );
        } );
        function handleChange( event ) {
            event.preventDefault();
    		const reg = /^[a-zA-Z0-9_.+-]+@(?:(?:[a-zA-Z0-9-]+\.)?[a-zA-Z]+\.)?(.*[a-zA-Z])\.(com|net|co)$/;
            if (reg.test(event.target.value)) {
                submitButtons.forEach( button => button.disabled = false );
            } else {
                alert('Invalid Email address detected');
                submitButtons.forEach( button => button.disabled = true );
            }
        }
    })();

    If you want to support more TLD’s just look at this section of code (com|net|co) to support more TLD’s just add them like to (com|net|co|cc).

    Cheers,

    Freddie

    Plugin Contributor Freddie

    (@fmixell)

    Actually, I used an arrow function in that example I would do this instead because it will be more compatible with older browsers.

    (function() {
        const emailInputs = document.querySelectorAll( 'input[type=email]' );
        const submitButtons = document.querySelectorAll( '.yikes-easy-mc-submit-button' );
        
        emailInputs.forEach( function( singleInput ) {
            singleInput.addEventListener( 'change', handleChange );
        } );
        function handleChange( event ) {
            event.preventDefault();
    		const reg = /^[a-zA-Z0-9_.+-]+@(?:(?:[a-zA-Z0-9-]+\.)?[a-zA-Z]+\.)?(.*[a-zA-Z])\.(com|net|co)$/;
            if (reg.test(event.target.value)) {
                submitButtons.forEach( function( button ) {
                   button.disabled = false;
                } );
            } else {
                alert('Invalid Email address detected');
                submitButtons.forEach( function( button ) {
                   button.disabled = true;
                } );
            }
        }
    })();
    Thread Starter milesbonnier

    (@milesbonnier)

    Thanks Freddie! I’ll look into it. Just to be clear, the code you sent me is compatible with the Easy Forms plugin js, so I only really need to add the js function as a custom? Kinda like a child theme?

    Sorta familiar with coding/js, but not so much in terms of WP integration.

    // Miles

    Plugin Contributor Freddie

    (@fmixell)

    @milesbonnier,

    Yes, I tested this on my Easy Forms development environment to make sure it would be compatible for you!

    Did you have any luck getting it to work for you?

    Cheers,
    Freddie

    Thread Starter milesbonnier

    (@milesbonnier)

    It’s perfect. Thanks Freddie ??

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Top-level domain wrong, but user still signed up.’ is closed to new replies.