Basically, the user clicks on a "Book" button, which is in a "Trip" node; the user then is redirected to a booking form (Webform) where he will fill in basic info for the reservation. I need to auto-fill a field in the form with the title of the node from where the user was redirected.

I tried to use the Rules module and I successfully made the redirection process, but I'm stuck on how to prepopulate the field with the title of the sender page.

I've never developed a custom module, I'm new to Drupal but I have programming experience, so if there is a straight way to accomplish this (contrib modules) that would be great. Alternatively, I'm not afraid of digging into code.

1 Answer 1


You could find the referring page by using $_SERVER['HTTP_REFERER'] in PHP and then lookup the node by using drupal_lookup_path and menu_get_object. At that point you then have the node object from the previous page and you can use "$node->title" to get the title you want.

$request_url =  $_SERVER['HTTP_REFERER'];
$host = $_SERVER['HTTP_HOST'] . "/";
$request_uri = explode($host,$request_url);
$path = drupal_lookup_path("source", $request_uri[1]);
$node = menu_get_object("node", 1, $path);

As far as how you put this into the webform, you could alter the submission using a hook or a specific component. I'm not aware of a module that lets you put PHP into a webform component. Potentially the Computed Field module (https://drupal.org/project/computed_field) could be of help.

Help from: How to get a node by its url alias?

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.