How can I customize an input value when the form is in lightbox?

  • Profile Image
    jacopogalli
    Asked on May 09, 2011 at 09:02 AM

    Hi to all, 

    I know how to pass a "dynamic" value to set an input field when the form is creating (URL GET params whith for example ?user_id=$php_var_user_id).

     

    But, what about if the form opens in lightbox? Something to set in your javascript code!?

     

    Thanks

    Jacopo

  • Profile Image
    liyam
    Answered on May 09, 2011 at 11:28 AM

    Hello Jacopo,

    Yes, this is still possible but you will need to create a javascript that will accept URL parameters and assign javascript variables to the lightbox script.

    You need add the property iframeParameters in your script.

    example:

    <script src="//www.jotform.com/min/g=feedback" type="text/javascript">
    new JotformFeedback({
    formId:'10563005897',
    base:'http://www.jotform.com/',
    iframeParameters: {
         'yourName15[first]': 'John',
         'yourName15[last]': 'Smith'
    },

    windowTitle:'test',
    background:'#FFA500',
    fontColor:'#FFFFFF',
    type:false,
    height:500,
    width:700
    });
    </script>

    On the above example, yourName15[first] & yourName15[last] are the field names in my form sample. The value beside it are values. If you wish for it to become a variable you will just need to remove the quotes (').

    example:
         'yourName15[first]':fname_param,
         'yourName15[last]':lname_param
     
     

    Posting URL parameters via javascript:

    Paste this script in your HTML file (anywhere as long as it is above your jotform feedback script):

    <script type="text/javascript">
    function getURLparameter( name )
    {
      name = name.replace(/[\[]/,"\\\[").replace(/[\]]/,"\\\]");
      var regexS = "[\\?&]"+name+"=([^&#]*)";
      var regex = new RegExp( regexS );
      var results = regex.exec( window.location.href );
      if( results == null )
        return "";
      else
        return results[1];
    }
    </script>

    Now let's go back to the jotform feedback script source.  You will need to declare your variable with the function in it.

    example:

    var fname_param = getURLparameter( 'yourName15[first]' );
    var lname_param = getURLparameter( 'yourName15[last]' );

     

    Place the variable declarations above of the jotform feedback script.

    example:

    <script src="//www.jotform.com/min/g=feedback" type="text/javascript">

    var fname_param = gup( 'yourName15[first]' );
    var lname_param = gup( 'yourName15[last]' );

    new JotformFeedback({
    formId:'10563005897',
    base:'http://www.jotform.com/',
    iframeParameters: {
         'yourName15[first]':fname_param,
         'yourName15[last]':lname_param
    },
    windowTitle:'test',
    background:'#FFA500',
    fontColor:'#FFFFFF',
    type:false,
    height:500,
    width:700
    });
    </script>

    Now save the file and test it.

    You can also check my sample running script and check the source code.  Feel free to change the parameter values:

    http://ravnos.t35.com/jotform_feedbackURLparams.html?yourName15[first]=John&yourName15[last]=Smith

    If you have other questions and inquiries, please let us know.

    Thanks

  • Profile Image
    dr770
    Answered on December 18, 2011 at 06:01 PM

    Hi liyam,

    i would like to provide a dynamic php variable (let say $ref) to lightbox, and be able to get the value per email.

    advice appreciated

    thanks a lot

    dovid

  • Profile Image
    idarktech
    Answered on December 19, 2011 at 05:03 PM

    @dr770,

    Thank you for asking. Please use this thread for answer/updates on your question. Thank you so much!

    http://www.jotform.com/answers/63481-dynamic-php-variable-to-lightbox#3