I am developing a site (Drupal 7, Omega sub-theme, panels & views). On every product page I have a link to the webform. I need the webform to register to which page the customer is referring. In other words, where is the link coming from, or what is URL of the last visited page? Is there a specific drupal way of doing this? Or any other way, for that matter? Thanks!
Relevant section from this tutorial (modified for a webform use-case) ... you will probably want to use the 'Prepopulate' module if you are trying to actually 'do stuff' e.g. pre-fill the webform with arguments from the url (aka the originating content type)...
"There are probably several ways how to do this, but the first thing which came to my mind was to add a block in views which can be shown on your originating content type and that will be used to create the link with the node id for your webform to process."
This is very simple in Views where you only need to add two fields and then place the block to a sidebar for example. The first field you need is the Content: Nid field and exclude it from display. Then you will add Global: Custom text and write the URL using the URL of the form (has to be configured when creating the webform), name of the field as key and [nid] token as the value in the URL. Image below should make it clear. The 'field_form_house_er' refers to a field on the webform that has it's field settings set to 'prepopulate from url'...(you'll need the pre populate module to do this)
Contextual filter has to be added also to the view which is providing the block using the option Provide default value -> Content ID from URL, or otherwise it won't activate.
After saving the view it can be placed to a sidebar for example and it will dynamically create the link every time you view a content of some type on your site. You will probably need different forms for different content types but with generic settings this setup will work with any content type if you have set up the form to allow any content type to be selected."
On you link display something like this :
$current_path = current_path(); $current_path_alias = drupal_get_path_alias($current_path); print url('my-webform', array('query' => array('from' => $current_path_alias )));
If you are on content/mynode, the link will display my-webform?from=content/mynode.
If you want just the unaliased path skip the use of
$current_path = current_path(); print url('my-webform', array('query' => array('from' => $current_path)));
If you are on node/18, the link will display my-webform?from=node/18.