How can I capture the email of a logged-in user on WordPress?

  • lucash
    Asked on February 8, 2017 at 8:57 AM

    Users must be logged in to submit my form, so I'd like to capture their email address from their login info rather than forcing them to type it. I've tried following the steps on this thread, but haven't gotten it to work.

    I installed Insert PHP.

    Form URL: https://www.jotform.com/build/70254644192152

    Code I've tried (I know it's long; I got it straight from JotForm):

    <iframe id="JotFormIFrame-70254644192152" onDISABLEDload="window.parent.scrollTo(0,0)" allowtransparency="true" src="https://form.jotform.com/70254644192152"?email=[insert_php] global $current_user; get_currentuserinfo(); echo $current_user->user_email;[/insert_php] frameborder="0" style="width:100%; height:909px; border:none;" scrolling="no"> </iframe> <script type="text/javascript"> window.handleIFrameMessage = function(e) { var args = e.data.split(":"); var iframe = false; if (args.length > 2) { iframe = document.getElementById("JotFormIFrame-" + args[2]); } else { iframe = document.getElementById("JotFormIFrame"); } if (!iframe) return; switch (args[0]) { case "scrollIntoView": iframe.scrollIntoView(); break; case "setHeight": iframe.style.height = args[1] + "px"; break; case "collapseErrorPage": if (iframe.clientHeight > window.innerHeight) { iframe.style.height = window.innerHeight + "px"; } break; case "reloadPage": window.location.reload(); break; } var isJotForm = (e.origin.indexOf("jotform") > -1) ? true : false; if(isJotForm && "contentWindow" in iframe && "postMessage" in iframe.contentWindow) { var urls = {"docurl":encodeURIComponent(document.URL),"referrer":encodeURIComponent(document.referrer)}; iframe.contentWindow.postMessage(JSON.stringify({"type":"urls","value":urls}), "*"); } }; if (window.addEventListener) { window.addEventListener("message", handleIFrameMessage, false); } else if (window.attachEvent) { window.attachEvent("onmessage", handleIFrameMessage); } if(window.location.href && window.location.href.indexOf("?") > -1) { var ifr = false; if (args.length > 2) { ifr = document.getElementById("JotFormIFrame-" + args[2]); } else { ifr = document.getElementById("JotFormIFrame"); } var get = window.location.href.substr(window.location.href.indexOf("?") + 1); if(ifr && get.length > 0) { var src = ifr.src; src = src.indexOf("?") > -1 ? src + "&" + get : src + "?" + get; ifr.src = src; } } </script>

  • Kiran Support Team Lead
    Replied on February 8, 2017 at 10:03 AM

    Please allow me some time to check on this on my local installation of WordPress and get back to you.

    Thank you for your patience. 

  • Kiran Support Team Lead
    Replied on February 8, 2017 at 12:40 PM

    Thank you for being patient. I have checked the code that you are using and see that a double quote (") in the code is misplaced which is causing the issue. Please remove the double quote after the form ID and place it after the [/insert_php] tag and the form should be displaying the email of the user logged in.

    How can I capture the email of a logged in user on WordPress? Image 1 Screenshot 20

    So, you can place the code below to the WordPress web page.

    <iframe id="JotFormIFrame-70254644192152" onDISABLEDload="window.parent.scrollTo(0,0)" allowtransparency="true" src="https://form.jotform.com/70254644192152?email=[insert_php] global $current_user; get_currentuserinfo(); echo $current_user->user_email;[/insert_php]" frameborder="0" style="width:100%; height:909px; border:none;" scrolling="no"> </iframe>

    This is working on my local installation. Please change the form embed code on your web page with the above code and let us know if you need any further assistance. We will be happy to assist. 

     

  • lucash
    Replied on February 8, 2017 at 1:19 PM

    Thanks, Kiran! It's working.