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.