- BxClinicAsked on September 06, 2017 at 08:11 AM
I have some forms which I'm very happy with. I'd like to integrate them deeper with Wordpress in this way:
I would like some fields (such as the "Name" "Email" and "Address" fields) of the Jotform to be prepopulated from the information stored against the logged in Wordpress user.
So, when the form is loaded, there should be an api to Wordpress, asking for the logged in user. Wordpress provides the name, email and address data and this is entered into Jotform. If there is no logged in user, then Wordpress would reply accordingly, and a "Please log in to the site message / page is displayed".
When we've achieved this, I'd also like completing one Jotform (signing up to a course via this form: https://eu.jotform.com/BxClinic/pre-pro-london) to send the information to Wordpress to create a user.
How do I go about achieving this please? I have a competent development team ready to do the work, so just need the information to point them in the right direction.
Jotform URLs are
- JotForm Supportashwin_dAnswered on September 06, 2017 at 10:22 AM
If I understand your question correctly, you want to populate your form fields with the details of wordpress logged in user. Is that correct?
Please note that it is not possible to populate form fields with data from any external source. One possible way to achieve your requirement is to write your own code in wordpress to read the data from your wordpress and then populate your form fields.
Though I am not PHP expert but I refereed wp site on how to get the data of logged in user. You will Here are the steps you need to follow but you will need PHP programming knowledge:
#1. Add PHP code in your wordpress page to read the data of currently logged in user.
Sample code to read the current user data:
$current_user = wp_get_current_user();
echo 'Username: ' . $current_user->user_login . '<br />';
echo 'User email: ' . $current_user->user_email . '<br />';
echo 'User first name: ' . $current_user->user_firstname . '<br />';
echo 'User last name: ' . $current_user->user_lastname . '<br />';
echo 'User display name: ' . $current_user->display_name . '<br />';
echo 'User ID: ' . $current_user->ID . '<br />';
You can refer the following guide on how to read the wp user data: https://codex.wordpress.org/Function_Reference/wp_get_current_user
#2. Above code should be added just before where you add in PHP source code of wp page or header.
#3. Instead of echo the value, store it in a global variable which can be accessible form any page.
#4. Add your form's iFrame embed code in your wp page and populate the form fields with the value from global variable by taking advantage of our URL parameter feature. The following guide should help you:
Get iFrame embed code: https://www.jotform.com/help/148-Getting-the-Form-iFrame-Code
Populate form fields: https://www.jotform.com/help/71-Prepopulating-Fields-to-Your-JotForm-via-URL-Parameters
Hope this helps.
Do try it out and see if this helps you. Unfortunately we will not be able to help you in custom programming in wordpress page.
- BxClinicAnswered on September 06, 2017 at 10:33 AM
Thanks Ashwin, that sounds like an excellent way to achieve the goal. I'll pass the info to my developers.