Support » Plugin: Newsletter » An email address can subscribe twice

  • Resolved spespam

    (@spespam)


    Hello,

    An email address can subscribe twice. I’m using this plugin with a pop-up and entered [newsletter_form button_label=”Go!” list=”1,2″]
    [newsletter_field name=”email” label=”Your best email”]
    [/newsletter_form]

    as shortcode. And found out that an email address can subscribe twice, even if it is already confirmed.

Viewing 10 replies - 1 through 10 (of 10 total)
  • ¿Did you find a solution for this? I’m having the same problem now.

    I have the same issue. Any fix??

    With a bit of tweaking, I finaly managed to fix it.

    In my theme’s function.php file:

    add_action('wp_head', 'pluginname_ajaxurl'); //needed to pass AJAX path for NEWSLETTER plugin modification (see below)

    function pluginname_ajaxurl() {
    ?>
    <script type="text/javascript">
    var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
    </script>
    <?php
    }

    function check_mail_THEME() {

    // The $_REQUEST contains all the data sent via ajax
    if (isset($_REQUEST)) {

    $mail = $_REQUEST['mail'];

    global $wpdb;
    $query = $wpdb->prepare("SELECT status FROM wp_newsletter WHERE email = %s", $mail);
    $status = $wpdb->get_var($query);

    echo $status;
    wp_die(); // Always die in functions echoing ajax content
    }
    }

    add_action('wp_ajax_nopriv_check_mail_THEME', 'check_mail_THEME');
    add_action('wp_ajax_check_mail_THEME', 'check_mail_THEME');

    and then in validate.js file in Newsletter plugin “subscription” folder:


    // this code at the top
    jQuery(document).ready(function ($) {
    var myForm = $('form#newsletterForm');
    var sendForm = false;
    myForm.submit(function (e) {
    if (!sendrForm) {
    e.preventDefault();
    }

    if (newsletter_check(this)) { // First I check fields

    var myMail = this.elements["ne"].value;

    $.ajax({// This does the ajax request
    url: ajaxurl,
    data: {
    action: "check_mail_THEME",
    correo: myMail
    },
    type: "POST",
    success: function (data) {
    if (!data) { // everything OK
    sendForm = true;
    myForm.submit();
    } else {
    switch (data) {
    case 'S': // already registered but not confirmed
    alert('Sorry, already registered but not confirmed');
    break;
    case 'C': // Fully registered
    alert('Sorry, mail already registered');
    break;
    }
    return false;
    }
    },
    error: function (errorThrown) {
    console.log(errorThrown);
    return false;
    }
    });
    }
    });
    });

    Obviously you won’t be able to update the plugin as one of its core files is been modified.

    With a bit of tweaking, I finaly managed to fix it.

    In my theme’s function.php file:

    add_action('wp_head', 'pluginname_ajaxurl'); //needed to pass AJAX path for NEWSLETTER plugin modification (see below)

    function pluginname_ajaxurl() {
    ?>
    <script type="text/javascript">
    var ajaxurl = '<?php echo admin_url('admin-ajax.php'); ?>';
    </script>
    <?php
    }

    function check_mail_THEME() {

    // The $_REQUEST contains all the data sent via ajax
    if (isset($_REQUEST)) {

    $mail = $_REQUEST['mail'];

    global $wpdb;
    $query = $wpdb->prepare("SELECT status FROM wp_newsletter WHERE email = %s", $mail);
    $status = $wpdb->get_var($query);

    echo $status;
    wp_die(); // Always die in functions echoing ajax content
    }
    }

    add_action('wp_ajax_nopriv_check_mail_THEME', 'check_mail_THEME');
    add_action('wp_ajax_check_mail_THEME', 'check_mail_THEME');

    and then in validate.js file in Newsletter plugin “subscription” folder:


    // this code at the top
    jQuery(document).ready(function ($) {
    var myForm = $('form#newsletterForm');
    var sendForm = false;
    myForm.submit(function (e) {
    if (!sendrForm) {
    e.preventDefault();
    }

    if (newsletter_check(this)) { // First I check fields

    var myMail = this.elements["ne"].value;

    $.ajax({// This does the ajax request
    url: ajaxurl,
    data: {
    action: "check_mail_THEME",
    mail: myMail
    },
    type: "POST",
    success: function (data) {
    if (!data) { // everything OK
    sendForm = true;
    myForm.submit();
    } else {
    switch (data) {
    case 'S': // already registered but not confirmed
    alert('Sorry, already registered but not confirmed');
    break;
    case 'C': // Fully registered
    alert('Sorry, mail already registered');
    break;
    }
    return false;
    }
    },
    error: function (errorThrown) {
    console.log(errorThrown);
    return false;
    }
    });
    }
    });
    });

    Obviously you won’t be able to update the plugin as one of its core files is been modified.

    @bohemme
    Thanks. I will implement this today and test on my site. Would it be possible to figure out how to copy over the core plugin file to a child theme structure so you wouldn’t loose the fix with an update. I am using a child theme but not sure how I’d need to copy the folder structure over to work.
    Thanks again! Now I just need to fix why the text for the emails isn’t responsive for size when viewed on mobile! Ugh.

    Hi! Well, if that’s possible, I couldn’t figure out how to do it. I mean overriding Newsletter’s own js file. I tried replicating the structure with no luck, so as my client was in a hurry, I left it like that. You know, low budget, no time left to invest. 🙂
    Maybe you may find out how and that way the plugin would be updateable. (though I made another modification so I’ll keep it out of the updatability). 🙂
    Don’t know anything about emails either. Sorry.

    Plugin Author Stefano Lissa

    (@satollo)

    What should be shown to a user trying to subscribe a second time (this option will be anyway added). An error message? You customer should worry about the user experience of giving an error message to a user shich want to subscriber and get back an error “you’re already subscribed”. “No, I’m not subscriberd I want to subscribe now and I want the welcome email where you give me access to my free content”.

    Just an example to consider :-).

    Stefano.

    I tried the above code but it didn’t work.
    If you subscribe an email that is already subscribed whether it’s confirmed or not I do not get any error message telling the user that the address is already subscribed.
    Any other way to fix this?

    I can’t remember having changed any more code, so maybe with echos and console.logs you can check out where the code is failing. I can assure that in my site works.

    And for my client, the functionality is clear: only new subscribers to the whole site will recieve a coupon with a discount, so the first time, they have this coupon. The second time they try, the system alerts that they are already subscribed and there’s no new coupon for them. 🙂

    I’ve checked the code, and there’s a typo:
    In javascript code, this line:
    if (!sendrForm) {
    should be
    if (!sendForm) {

    and also, at the end of that validate.js file, you also need the field validation functions:

    function newsletter_check_field(field, message) {
        if (!field)
            return true;
        if (field.type == "checkbox" && !field.checked) {
            alert(message);
            return false;
        }
        if (field.required !== undefined && field.required !== false && field.value == ""){
            alert(message);
            return false;
        }
        return true;
    }
    function newsletter_check(f) {
        var re = /^([a-zA-Z0-9_\.\-\+])+\@(([a-zA-Z0-9\-]{1,})+\.)+([a-zA-Z0-9]{2,})+$/;
        if (!re.test(f.elements["ne"].value)) {
            alert(newsletter.messages.email_error);
            return false;
        }
        if (!newsletter_check_field(f.elements["nn"], newsletter.messages.name_error))
            return false;
        if (!newsletter_check_field(f.elements["ns"], newsletter.messages.surname_error))
            return false;
        for (var i = 1; i < newsletter.profile_max; i++) {
            if (!newsletter_check_field(f.elements["np" + i], newsletter.messages.profile_error))
                return false;
        }
        if (!newsletter_check_field(f.elements["ny"], newsletter.messages.privacy_error))
            return false;
        return true;
    }

    if not, it will throw a javascript error. As this functions where already there, I took it for granted that you’ll have left them there.

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘An email address can subscribe twice’ is closed to new replies.