0

I have been tasked with having to setup a cookie that records when an anonymous user closes a newsletter signup webform block so that it no longer appears when reloading the current page or navigating to another page on a website.

Can anyone please advise if there is module that performs this function?

Or can someone please point me in the right direction in terms of the correct code snippet I can use to make this work?

Many thanks!

3
  • What you meen by "user closes a newsletter signup webform block" ?.Solution is simple as: create a simple event on "user closes webform click" check whatever your anonymous and set cookie with php setcookie function. And check whatever your cookie is already defined, then dont show webform on your node.tpl.php. If you want to find a solution, post some more information, or code. Jan 22, 2016 at 12:29
  • Hi Neok. The webform block has a close function on the front end, so when they click the "X" it hides the form. I need to set a cookie that captures that event of the user closing the form and then saves it as a user session that keeps the form hidden while the user is navigating around the website. Jan 22, 2016 at 12:48
  • Still researching Jan 22, 2016 at 14:42

1 Answer 1

0

First you need to create a custom module and add javascript user identificator on your page with web form(to find out user anonymous or not) Here is example

Next use jquery library and do the next thing:

// its just an example you need to put your #id or .class
$("#subform_close").on('click', function() {
      if(Drupal.settings.user_js_uid == 0)
           {
              // set cookie for whatever you want
              $.cookie("dont_show_web_form", 1, { expires : 1 });
          }
})

and in your php code check for that cookie

$_COOKIE["dont_show_web_form"] 

and hide your webform.

1
  • Its not a full answer, I showed the direction in which to look. Jan 22, 2016 at 14:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.