I'm trying to figure out if doing this is possible. I'm not very good at php so I'm trying to avoid having to create a module or something else to do this.

What I am trying to do is this: In the default value field for a section in my webform, $_SERVER["REQUEST_URI"] to return the URL that the form is on, however, the entire URL is retrieved. (/cms/?q=content/82245940-initial-services) I want to cut out the non-identifying part of the URL so that I'm left with 82245940-initial-services. Is there a way to code this into the default value field(1 line), or do I need to create special code to do this?

Something like this: $_SERVER["REQUEST_URI"-"http://example.com/cms/?q=content"]

  • how are you linking to this form?
    – uwe
    Oct 20, 2011 at 5:21
  • @monotribe Actually I have the form setup so that it only shows up on the pages that I want it to. I currently have it set up as a block that is configured to show up on pages whose URL has this: content/8*. The reason I did this was because the eight digit number starting with the number '8' is the work order for tasks that are created. And I need the form to be associated with only tasks, not projects, organizations or other content types in the Storm project management module. If there is a better way to do this, I am open.
    – Michael
    Oct 20, 2011 at 11:16

2 Answers 2


If you'r working with drupal you should use drupal_get_path_alias()

$path = drupal_get_path_alias();
$value = str_replace('content/', '', $path);
  • I guess I'm confused where I would put this code. If I put it directly into the Default Value field for a textfield, the php isn't evaluated and all I get is, "$path = drupal_get_path_alias(); $value = str_replace('content/', '', $path);". If I put it in a Markup Field, I still get the same thing. If you could tell me where I should be putting it, I would appreciate it very much.
    – Michael
    Oct 20, 2011 at 12:22

you could use the prepopulate module to pre-fill a form based on the URL

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.