1

I have a newsletter sign-up form in a block that appears on many pages. When the form is submitted, I want to capture the current page.

The block and form are created in code. In the submit function, I am using drupal_get_path_alias() to get the current location. The block has no explicit caching set, so I believe DRUPAL_CACHE_PER_ROLE is assumed.

I had been thinking that although the block is cached for anonymous users, the submit function would still retrieve the correct location.

However, it doesn't seem to be working correctly. I always get a value for the path, but I believe it's incorrect in many cases.

What should I do to make sure I get a correct path on submit?

Update Mar 17 2014: I switched caching from the assumed DRUPAL_CACHE_PER_ROLE to DRUPAL_CACHE_PER_PAGE and that seems to have resolved the problem. Also, for the record, the problem looked like this: most sign-ups come from one page. But every once in a while a sign up will come from a different more obscure location on the site. What I was seeing was that "other location" repeated for the next x of signups (the number varied). So, in that respect, it did look like a caching problem.

1

have you fully tested your guess? what you've described should work, AFAIK.

other options would include:

1) modifying the form to have a hidden value, set using drupal_get_path_alias() ... it would set the value on load, rather than looking it up on submit.

2) a google analytics event tracker attached to the submit button the form.

  • I need to do some more testing for sure. About 2 days ago I noticed when I was testing as an anon user, the page location wasn't always accurate (though it always had a value). Which made me think that somehow I was getting the location of other anon users. Both of your ideas as workaround are good - thanks. – Dave Bruns Mar 13 '14 at 19:57

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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