Is it possible to automatically grab Wordpress user details and add them to form?

  • Profile Image
    ccranney
    Asked on April 03, 2014 at 10:16 AM

    I have an uploader on our website which uses Jotform. I am integrating the uploader in to a special section of the website which requires the user to login. Is there anyway that the Jotform can detect which user has uploaded a file so I do not have to ask them again for their contact details etc?

  • Profile Image
    EltonCris
    Answered on April 03, 2014 at 11:51 AM

    Hi,

    That's possible but you have to use custom php script (which you can try below) in order to retrieve the information pertaining to the current logged in user on your WP site.

    Here's how:

    1. Get your iframe embed code. http://www.jotform.com/help/148-Getting-the-Form-iFrame-Code

    2. Edit your iframe embed code. Append the following URL parameter on the src value found on your iframe embed code to populate the current logged in user to the username field on your form.

    ?username=<?php global $current_user; get_currentuserinfo(); echo $current_user->user_login;?>

    username is the field name on your form where you want to populate the data.

    The final code should look similar to this:

    <iframe id="JotFormIFrame" onload="window.parent.scrollTo(0,0)" allowtransparency="true" src="https://secure.jotformpro.com/form/40924949465972?username=<?php global $current_user; get_currentuserinfo(); echo $current_user->user_login;?>" frameborder="0" style="width:100%; height:465px; border:none;" scrolling="no"></iframe>

    3. Embed the modified iframe embed code to your WP site.

    Let us know if you have difficulties implementing this. Thanks!

  • Profile Image
    ccranney
    Answered on April 07, 2014 at 03:51 AM

    @EltonCris

    I have tried as above but the username is not being auto populated :(.

    Here is the code I have used:

    <iframe id="JotFormIFrame" onload="window.parent.scrollTo(0,0)" allowtransparency="true" src="//form.jotformeu.com/form/40753265708357?Username=<?php global $current_user; get_currentuserinfo(); echo $current_user->user_login;?>" frameborder="0" style="width:100%; height:1107px; border:none;" scrolling="no"></iframe>

    <script type="text/javascript">window.handleIFrameMessage = function(e) {var args = e.data.split(":");var iframe = document.getElementById("JotFormIFrame");if (!iframe)return;switch (args[0]) {case "scrollIntoView":iframe.scrollIntoView();break;case "setHeight":iframe.style.height = args[1] + "px";break;}};if (window.addEventListener) {window.addEventListener("message", handleIFrameMessage, false);} else if (window.attachEvent) {window.attachEvent("onmessage", handleIFrameMessage);}</script>

     

    Any ideas what could be the problem?

  • Profile Image
    Welvin
    Answered on April 07, 2014 at 08:26 AM

    I don't see a username field to the form on this webpage: http://hotcost.co.uk/uploader/. What is the correct form URL?

    Also, please use the exact codes given by my colleague, use small caps for the field name and use just the codes below:

    <iframe id="JotFormIFrame" allowtransparency="true" src="//form.jotformeu.com/form/40753265708357?username=<?php global $current_user; get_currentuserinfo(); echo $current_user->user_login;?>" frameborder="0" style="width:100%; height:465px; border:none;" scrolling="no"></iframe>

    Still, the "username" should be the field name of your form. Let us know the form URL and we'll give you the final codes.

    Thanks

  • Profile Image
    ccranney
    Answered on April 07, 2014 at 08:56 AM

    The URL is here: http://hotcost.co.uk/customer-area/pages/create-page/

     

    You will need to login, please use: 

    jotform

    Password1

     

    I only changed the username to caps as I named it as such in the form. Will this work if I hide the username field? Thanks.

  • Profile Image
    Welvin
    Answered on April 07, 2014 at 10:30 AM

    Thank you. Please use the following codes:

    <iframe id="JotFormIFrame" allowtransparency="true" src="//form.jotformeu.com/form/40753265708357?username32=<?php global $current_user; get_currentuserinfo(); echo $current_user->user_login;?>" frameborder="0" style="width:100%; height:465px; border:none;" scrolling="no"></iframe>

    username32 is the field name of the "username" field. When I say "small caps", I'm referring to the actual field name, not to the field label.

    You can find the field name by following this guide: How to Find Field IDs & Names.

    Update us here for the results after using the codes above.

    Thanks

  • Profile Image
    ccranney
    Answered on April 09, 2014 at 10:48 AM

    Unfortunately this is still not working, the username field is always blank when a submission is made.

     

    Any ideas what the problem may be?

     

    Thanks

  • Profile Image
    ashwin_d
    Answered on April 09, 2014 at 12:04 PM

    Hello ccranney,

    Upon checking your webpage, I found that the iFrame URL has lot of unwanted character. It may be because you have copy pasted it directly from here in your html editor. Please check the screenshot below:

    I would suggest you to copy the code from the following location and that should solve your problem:  http://pastie.org/9053293

    Do get back to us if the issue persists.

    Thank you!

  • Profile Image
    ccranney
    Answered on April 10, 2014 at 03:44 AM

    Thanks. I retried using that code but the issue unfortunately remains :(

     

    No username data is being transfered over. I have tried this with different people being logged in to Wordpress but it still does not work.

     

    Thanks

  • Profile Image
    EltonCris
    Answered on April 10, 2014 at 08:36 PM

    @ccranney 

    The reason why it's not working because the PHP is not executed on your page. You have to install a plugin first where it allows you to execute PHP anywhere on your posts or pages.

    1. I found Insert PHP Plugin helpful. Please install this on your WP site so you can run a PHP codes. Here's how:

    2. Re-embed your form using this code:

    <iframe id="JotFormIFrame" allowtransparency="true" src="//form.jotformeu.com/form/40753265708357?username32=[insert_php] global $current_user; get_currentuserinfo(); echo $current_user->user_login; [/insert_php]" frameborder="0" style="width:100%; height:465px; border:none;" scrolling="no"></iframe>

    Insert PHP plugin usage:

    In order to run PHP, just wrap the PHP codes with [insert_php] and the closing tag [/insert_php] tags instead of <?php and ?>. Notice how this is applied to the codes above.

    Hope this helps!

    P.S. This is tested on my local WP page and it's working as expected.

  • Profile Image
    JohnReaves
    Answered on June 19, 2014 at 01:44 PM

    This is exactly something I need to do.  Hopefully this thread is still active; I'll try to implement this over the next week or so.  Thanks!
  • Profile Image
    Andre
    Answered on March 11, 2017 at 12:41 AM

    Hello,

    Has a solution been found? 

    get_currentuserinfo() is now changed to https://codex.wordpress.org/wp_get_current_user

     

    I have followed the above but still not working

     

    here is my code

    <iframe id="JotFormIFrame-70637934926467" onload="window.parent.scrollTo(0,0)" allowtransparency="true" src="https://form.jotform.me/70637934926467?email=<?php $current_user = wp_get_current_user(); echo $current_user->user_email;?>" style="overflow:hidden;height:100%;width:100%" height="150%" width="150%" border:none;"> </iframe>

     

    my field id is #input_10 and the unique field name is email, I've tried both still not working

     

    I tried the insert php plugin also not working, my wordpress version 4.7.3(latest as of this posting date).

    Any suggestion?

  • Profile Image
    activyco
    Answered on March 11, 2017 at 12:46 AM

    Sorry I have to take my word back,

     

    Success!!

     

    <div><iframe id="JotFormIFrame-70637934926467" style="overflow: hidden; height: 100%; width: 100%;" src="https://form.jotform.me/70637934926467?email=[insert_php] $current_user = wp_get_current_user(); echo $current_user->user_email;[/insert_php]" width="150%" height="150%"> </iframe></div>