Viewing 14 replies - 1 through 14 (of 14 total)
  • +1 for me!

    I want to use this for a signup form. When someone signs up instead of closing the box, I like the box not to appear when this user comes back to the page.

    mp1985

    (@mattia1985)

    I’m looking for the same thing… is it possible set the cookie when the form is submitted?

    +1

    I’m trying to use it with Contact Form 7 but didn’t quite get it yet. Has anyone figured what’s the configuration for CF7 form to enable the STB cookie and close the box?

    Plugin Author Danny van Kooten

    (@dvankooten)

    Hey all,

    I’m currently working on a huge update for the plugin, definitely taking this into account. While it won’t make it into the new version immediately, it makes it a lot easier to implement this kind of changes. 🙂

    Just letting you know I’m not forgetting about this plugin.

    Thank you Danny. Nice work. Any hints in the meantime, before that update?

    peteremil

    (@peteremil)

    That is seriously good news. Am curious!

    Was this request ever implemented?

    I have my box working as it should, but don’t want the box to show up if the user hit the submit button. I’m not sure how I can write a cookie to make sure the box is dismissed.

    So, after looking through the support history, I figured out how to set a cookie if the user submits the form so that the box isn’t displayed again (I put this in my functions.php file and I use Mailchimp for WordPress for my form).

    The problem now is… this hides all boxes. Is there a way for me to adjust the cookie so that is only hides the box ID that contained the form?

    function my_prefix_set_mailchimp_cookie($email, $merge_vars, $form_id, $result) {
    	if($result == true) {
    		setcookie("mc4wp_subscribed", $email, time() + 7776000, '/');
    	}
    }
    
    add_action('mc4wp_after_subscribe', 'my_prefix_set_mailchimp_cookie', 10, 4);
    
    function my_prefix_show_stb_box($matched, $box_id) {
    	if(isset($_COOKIE['mc4wp_subscribed'])) {
    		return false;
    	}
    	return $matched;
    }
    add_action('stb_show_box', 'my_prefix_show_stb_box', 10, 2);
    Plugin Author Danny van Kooten

    (@dvankooten)

    @limee78,

    While this request hasn’t been implemented yet, you’re nearly there! A way to only hide your box is to set a cookie named stb_12, where in this example 12 is the ID of your box.

    Example

    $box_id = 12;
    setcookie( 'stb_box_' . $box_id, true, time() + MONTH_IN_SECONDS, '/' );

    That way, you can ditch the second filter altogether so the complete code becomes like this.

    function my_prefix_set_mailchimp_cookie($email, $merge_vars, $form_id, $result) {
    	if($result === true) {
    		setcookie( 'stb_box_12', 'true', time() + 7776000, '/');
    	}
    }
    
    add_action('mc4wp_after_subscribe', 'my_prefix_set_mailchimp_cookie', 10, 4);

    Does that help?

    In the meantime, I’ll do my best to speed up my process of coming up with a general solution! Sorry for the wait all – definitely not forgotten though!

    Hi Danny,

    Thank you, thank you! This totally worked! I really appreciate you helping me.

    Is there a way for me to include the cookie set by MC4WP? I just realized that plug-in also sets a cookie called mc4wp_email.

    Is it possible to incorporate that into function we just created so past subscribers don’t get the pop-up either until the cookie expires?

    Hi all, just a quick note to let you know I’m curious about the implementation Danny talked about 🙂
    Keep up the good work & hope to hear from you soon!

    Perhaps a noob question, but where can I find the ID of the box?

    Plugin Author Danny van Kooten

    (@dvankooten)

    Hey Peter,

    I just pushed out an update of the plugin that adds the ID of the box to the overview page, where you see all of your boxes. That should help. 🙂

    Also, I’ve made it so that now when ANY form inside the box is submitted, the cookie that hides the box on consecutive page loads is automatically set. This means that your visitor no longer has to manually close the box after interacting with your form.

    If you want to disable this behaviour, shoot me a message here and I’ll provide you with some code that does just that. 🙂

    Thanx Danny! Hopefully I’ll start tinkering with the update later on this week. I’ll let you know when I have issues.

Viewing 14 replies - 1 through 14 (of 14 total)
  • The topic ‘Close box and set cookie when form submitted’ is closed to new replies.