Get WordPress user information to JotForm

  • Profile Image
    roffe
    Asked on February 27, 2018 at 07:12 AM

    I've managed to successfully embed JotForms with WordPress. I'm now looking for more customization.

    Is there a way for an embedded JotForm to collect user information from user profiles? That is, instead of a user typing in name and email, can a JotForm collect that data from a registered user's info?

    Any and all hints and tips appreciated.

    Thank you, 

  • Profile Image
    Adrian
    Answered on February 27, 2018 at 08:57 AM

    This is possible if you embed the form using the Iframe method.
    Getting the Form iFrame Code

    You would also need to allow PHP execution on your pages. Install this plugin first.
    https://wordpress.org/plugins/insert-php/

    If this is the form that you are trying to embed, try using the following Iframe code:

    <iframe

      id="JotFormIFrame-80432089835360"

      onload="window.parent.scrollTo(0,0)"

      allowtransparency="true"

      allowfullscreen="true"

      src="https://form.jotformeu.com/80432089835360?[insert_php]$current_user = wp_get_current_user(); echo 'harDu6=' . $current_user->user_email . '&hvaHeter[first]=' . $current_user->user_firstname . '&hvaHeter[last]=' . $current_user->user_lastname;[/insert_php]"

      frameborder="0"

      style="width: 1px;

      min-width: 100%;

      height:539px;

      border:none;"

      scrolling="no"

    >

    </iframe>

    <script type="text/javascript">

      var ifr = document.getElementById("JotFormIFrame-80432089835360");

      if(window.location.href && window.location.href.indexOf("?") > -1) {

        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;

        }

      }

      window.handleIFrameMessage = function(e) {

        var args = e.data.split(":");

        if (args.length > 2) { iframe = document.getElementById("JotFormIFrame-" + args[(args.length - 1)]); } 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;

          case "loadScript":

          var src = args[1];

          if (args.length > 3) {

            src = args[1] + ':' + args[2];

          }

          var script = document.createElement('script');

          script.src = src;

          script.type = 'text/javascript';

          document.body.appendChild(script);

          break;

          case "exitFullscreen":

          if      (window.document.exitFullscreen)        window.document.exitFullscreen();

          else if (window.document.mozCancelFullScreen)   window.document.mozCancelFullScreen();

          else if (window.document.mozCancelFullscreen)   window.document.mozCancelFullScreen();

          else if (window.document.webkitExitFullscreen)  window.document.webkitExitFullscreen();

          else if (window.document.msExitFullscreen)      window.document.msExitFullscreen();

          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);

      }

    </script>

    Related Articles:
    Prepopulating Fields to Your JotForm via URL Parameters
    https://codex.wordpress.org/Function_Reference/wp_get_current_user

  • Profile Image
    Adrian
    Answered on February 27, 2018 at 09:00 AM

    You can also get the Iframe code from here: https://pastebin.com/raw/6KNyJuXq

    Let us know how this works out for you.

  • Profile Image
    roffe
    Answered on February 28, 2018 at 07:36 AM

    Awesome. Thanks! :)