-
tonystarksAsked on March 20, 2018 at 9:38 AM
I have a form embedded in a SharePoint. We want to get the email of the user logged in it and have it prepopulated or maybe include it in the output.
-
AdrianReplied on March 20, 2018 at 11:35 AM
If I understand you correctly, you want to get the email address of the logged in user in SharePoint and prepopulate the form with it.
Prepopulating the form is quite easy. You can generate the prepopulated URL using our PrePopulate Application. http://prepopulate.jotform.io/
Complete Guide: Prepopulating Fields to Your JotForm via URL Parameters
To get the email of the currently logged in user, try the following C# code.
SPWeb web = SPContext.Current.Web;
web.CurrentUser.Email;
-
tonystarksReplied on March 20, 2018 at 11:27 PM
Yes you are correct. That's what i want to accomplish. But i'm not sure where to put the C# codes in the form.
-
Elton Support Team LeadReplied on March 21, 2018 at 5:26 AM
If it's the username from Sharepoint that you want to get, you can try the script provided on this page https://stackoverflow.com/questions/20981226/sharepoint-2013-get-current-user-using-javascript.
Then you can prepopulate it in your form through URL parameter.
To do that, you need to add a username field in your form and then make it hidden or whichever you prefer.
Then in your embed code, you will have to construct it like the following to catch the username value.
Example:
<div id="jot"></div>
<script type="text/javascript">
var username="John";
var ifrm = document.createElement("iframe");
ifrm.setAttribute("src", "https://form.jotform.com/80786173691972?username="+username);
ifrm.style.width = "100%";
ifrm.style.height = "480px";
ifrm.style.border = "0";
document.getElementById("jot").appendChild(ifrm);
</script>
You need to pass the value into the variable username so it would be populated to the form.
Also, replace the form URL above with your form URL. You also need to adjust the width and height of the frame.