Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • dominik 711 posts 733 karma points
    Apr 29, 2011 @ 09:46
    dominik
    0

    Get referer as hidden variable in template

    Hi,

    Is there any way to get the current URL (referer) inside a form as hidden variable?

    for example inside my form i get the following:

    <form action="">
    <input type="hidden" name="referer" value="CURRENT-URL">

     

    Thanks

  • Rich Green 2246 posts 4008 karma points
    Apr 29, 2011 @ 10:00
    Rich Green
    0

    This should work in XSLT

    <input type="hidden" name="referer" value="{umbraco.library:Request('UrlReferrer')}"/>

    Rich

  • dominik 711 posts 733 karma points
    Apr 29, 2011 @ 10:22
    dominik
    0

    sorry i think it was a little bit unclear.

    I do not need it in xslt i just want to get the current page URL inside a hidden form tag to use it as refererer url inside a usercontrol.

    So just want to know how to get the current URL of the site inside a hidden Variable

  • Rich Green 2246 posts 4008 karma points
    Apr 29, 2011 @ 10:56
    Rich Green
    0

    Something like this

    <form action="">
    <input type="hidden" name="referer" value='<%="http://" & Request.ServerVariables("SERVER_NAME") & Request.ServerVariables("URL")%>'>
    </form>

     Rich

  • dominik 711 posts 733 karma points
    Apr 29, 2011 @ 11:05
    dominik
    0

    hi Rich,

    Now i get the following error:

    Non-invocable member 'System.Web.HttpRequest.ServerVariables' cannot be used like a method.

     


  • dominik 711 posts 733 karma points
    Apr 29, 2011 @ 11:15
    dominik
    0

    I found it out

    It must be

                  <input type="hidden" name="referer" value='<%="http://" + Request.ServerVariables["SERVER_NAME"] + Request.ServerVariables["URL"]%>'>             
  • Rich Green 2246 posts 4008 karma points
    Apr 29, 2011 @ 11:19
    Rich Green
    0

    My mistake

    <form action="">
    <input type="hidden" name="referer" value='<%="http://" & Request.ServerVariables["SERVER_NAME"] & Request.ServerVariables["URL"]%>'>
    </form>
  • Rich Green 2246 posts 4008 karma points
    Apr 29, 2011 @ 11:29
    Rich Green
    0

    Cross post, glad you got it working!

  • Michael Latouche 504 posts 819 karma points MVP 4x c-trib
    Apr 29, 2011 @ 11:54
    Michael Latouche
    0

    Hi,

    Just for info, I think you can achieve the same with this:

     <input type="hidden" name="referer" value='<%=Request.Url.AbsoluteUri%>'>             

    With the advantage that you do not hardcode the "http" part (can be handy if some parts of the site fall in https for example).

    Cheers,

    Michael.

Please Sign in or register to post replies

Write your reply to:

Draft