Prepopulating multiple fields with data from WordPress

  • Profile Image
    BensonIPG
    Asked on February 04, 2021 at 10:28 AM

    Hello,


    I currently have my form set up where it pulls a user's login from wordpress to populate a username field through Insert PHP. I also want to pull their email address from wordpress but cannot seem to get it to work correctly and was wondering if there was a way to populate both fields. Below is the embed code I am using that works correctly for just the username:


    <script type="text/javascript" src="https://form.jotform.com/jsform/203265018354147?username=[insert_php] global $current_user; get_currentuserinfo(); echo $current_user->user_login;[/insert_php]"</script>


  • Profile Image
    Welvin
    Answered on February 04, 2021 at 12:54 PM

    For the email address, you should use the following parameter:

    $current_user = wp_get_current_user();
    echo $current_user->user_email;

    For reference: https://developer.wordpress.org/reference/functions/wp_get_current_user/.

    This will only work if you have the form embedded on the core PHP file of the page or if you have a plugin that can run PHP codes on your WordPress page.

    Thanks

  • Profile Image
    BensonIPG
    Answered on February 04, 2021 at 05:31 PM

    Thank you for the response! I have a plugin that runs PHP and does great for the user name but can't figure out where to put the email parameter code or if its even possible to add a second parameter to the in-line URL embedded in the form. Would you be able to look at the code below and see where I would add the code for the email or if it is even something that is able to be done?

    <script type="text/javascript" src="https://form.jotform.com/jsform/203265018354147?username=[insert_php] global $current_user; get_currentuserinfo(); echo $current_user->user_login;[/insert_php]"</script>

    **

    Sorry, I got it figured out now, thank you for your help!