Get current url and set as hidden field value

  • Profile Image
    Asked on July 17, 2012 at 08:15 PM

    Hi !!!

    I have a hidden field in my form. I have embedded this form in my website, and I need to get current url and set this url as value in my hidden field. 

    In order to do this, I have set as default value in my hidden field a php instruction: <?php echo $_SERVER['REQUEST_URI']; ?>.

    Unfortunatly, when i submit the embedded form this hidden field appears blank. 

    How can I obtain current URL and submit as the value of the hidden field?

    Thanks in advance.


  • Profile Image
    Answered on July 17, 2012 at 08:40 PM

    The form itself is an HTML page, not a PHP one, so it cannot execute PHP functions. Therefore, setting a PHP function as your hidden field's default value will not work.

    If the page where you have embedded the form is a php file, it is better to prepopulate the form with that php function using URL parameters.

    Try the codes below:

    <iframe allowtransparency="true" src="//<?php echo $_SERVER['REQUEST_URI']; ?>" frameborder="0" style="width:100%; height:560px; border:none;" scrolling="no">

    Please note that you will have to remove the hidden field's default value first (via JotForm).

  • Profile Image
    Answered on July 17, 2012 at 08:46 PM

    Hi Minesh,

    I also did it by adding client-side javascript only.


    <input type="hidden" class="form-hidden" value="" id="input_10" name="q10_myurl" />  

    <script type="text/javascript">

    document.getElementById('input_10').value = document.URL;


    input_10 is the hidden field.
    I thought I should also share. More selection option is better =) 
  • Profile Image
    Answered on January 18, 2016 at 03:25 AM