We need to have our logged-in users' data (
First Name ,
Last Name) pre-fill the links to Google Forms existing on our site.
We have Google Forms spread out on our site that our students (youngsters aged 6-11) under the customized role
students, take as tests. The problem is that they keep making mistakes when writing their names, emails, etc.
The links to the forms look like: Click here for the test
So, we would like to pre-fill these various links with their User Data as they are stored in the WordPress database.
This is the actual link for the demo form for this post:
We always keep the same pattern (as far as structure goes) for the first sections that identify the student.
If we use the pre-fill feature of the form for:
LoginName: STUDENT 01 Email: firstname.lastname@example.org FirstName: First LastName: Last
We get the following link:
Breaking down and analyzing the link, we notice the following parts:
1st part of the link: telling Google it is a form
2nd part of the link: the ID of the specific form
3rd part of the link
/viewform/followed by a
4th part of the link: this is where exist the positions and the data of the pre-fill.
Since we always keep -as mentioned- the same structure, we will always get the same positions joint by
How to solve
I think that using an
if action that combines
current_user_can( 'student' ) ,
public function init ,
wp_get_current_user() and maybe some JS with
onclick could solve this issue by replacing the above mentioned data with the ones retrieved from WordPress for a logged-in student for every link starting with the 1st part that identifies a Google Form.
Unfortunately I am lost on how to do this. So.
How could one pre-fill Google Forms URLs with logged in WordPress user's data?
Or in other words:
How to dynamically populate already existing external links with user data in WordPress.
EDIT: Further clarification
There is not just one Google Form present, but many. This means that the 2nd part of the URL (Form ID ) is constantly changing.
So the workflow to the solution could be an action where:
If user has the role
student (or is logged)
And if any given URL starts with
Keep the part of the
looooong Form ID until the next
entry.646601418= And (dynamically) Fill in
current Login Name
entry.280532864= And (dynamically) Fill in
entry.1176284616= And (dynamically) Fill in
current First Name
entry.165661554= And (dynamically) Fill in
current Last Name
onclick for non-admin pages the new URL