Help

This Product Ideas board is currently undergoing updates, but please continue to submit your ideas.

WordPress user data prefill

cancel
Showing results for 
Search instead for 
Did you mean: 
Ed_Furilla
5 - Automation Enthusiast
5 - Automation Enthusiast

A good feature would be to set up the ability to prefill a form with current wp user data. This would allow the logged in user to have their name, email etc. included in the form.

10 Comments
W_Vann_Hall
13 - Mars
13 - Mars

Are you calling the form from a WP page? If so, you should be able to pass the values as part of the URL string using get_query_var(). (See this discussion, among others.)

Casey
6 - Interface Innovator
6 - Interface Innovator

I’d like to know more about this. With respect to the Airtable part, how do we format the URL?

Ed_Furilla
5 - Automation Enthusiast
5 - Automation Enthusiast

"<iframe class=“airtable-embed” style=“background: transparent; border: 1px solid #ccc;” src=“https://airtable.com/embed/shrRMSNCSSaPw8BDG?backgroundColor=blue&prefill_Name=(I would like WP User Display Name); width=“100%” height=“1000” frameborder=“0”>”

If i put in a fixed text (e.g., John Doe) the name does fill in the name field. I came to the conclusion that I couldn’t pass WP user data but maybe I am incorrect.

I also added code to the functions.php file as follows…

<?php // [airtableform form_id="shrRMSNCSSaPw8BDG" color="blue"] function airtableform_func( $atts ) { $a = shortcode_atts( array( 'form_id' => '', 'width' => '100%', 'height' => '1100', 'color' => 'red', ), $atts ); $current_user = wp_get_current_user(); $prefill_string = ""; if ( $current_user->exists() ) { $prefill = [ "Name" => $current_user->user_displayname, "email" => $current_user->user_email ]; foreach($prefill as $key => $value){ $prefill_string .= "&prefill_" . rawurlencode($key) . "=" . rawurlencode($value); } } return ''; } add_shortcode( 'airtableform', 'airtableform_func' );
W_Vann_Hall
13 - Mars
13 - Mars

The information on Airtable prefill (only for form views) can be found here. There are a number of caveats and tricks, so a search for ‘/prefill’ in Airtable Community may prove valuable.

W_Vann_Hall
13 - Mars
13 - Mars

I’ll be honest: All my WP-to-Airtable integration has been through @Chester_McLaughlin’s excellent Airpress WP plug-in. I’d stumbled across the reference to populating URLs using WP variables while researching options for a prospect who ultimately decided not to use WP,¹ so I’m afraid I’ll have to defer to the WordPress experts here…


  1. …or Airtable, for that matter, because he’d evidently just been given an iPad and had decided not to use any software whose iOS implementation wasn’t a mirror image of its Windows and browser implementations. I sometimes wonder how well that principled stand has worked out for him…
Chester_McLaugh
9 - Sun
9 - Sun

@W_Vann_Hall Thanks for the shoutout.

Here’s a thread on the Airpress support forum addressing just such a use case (and the solution doesn’t even require Airpress):
https://wordpress.org/support/topic/pass-user-information-to-airtable/

And here’s the info on how to do it:
Yes, this is possible and doesn’t require Airpress to work. If you place the code below into your functions.php file you’ll have a shortcode that allows you to embed a form and prefill specific fields

Airtable Prefill:

5f73751092c6afb3485d0dfe997b3809227f5002.png

Prefilling a form

When making an Airtable form, you can use prefill_ parameters in the URL of the form to prefill specific fields. Find the URL for the form you wish to prefill. Once you get the form URL, you can ...

WordPress User:
https://codex.wordpress.org/Function_Reference/wp_get_current_user

Working Example:

https://gist.github.com/chetmac/e55899bd14dcf803846ad524c538c248

functions.php
<?php

// [airtableform form_id="shr1St9pPOAptb7r8"]
function airtableform_func( $atts ) {

	$a = shortcode_atts( array(
		'form_id' => '',
		'width' => '100%',
		'height' => '533',
		'color' => 'red',
This file has been truncated. show original

Ed_Furilla
5 - Automation Enthusiast
5 - Automation Enthusiast

Chester, I really appreciate the help but I remain stuck. I believe I have implemented the code as described above exactly as written but to no avail.

What I am getting is the ability to Prefill a fixed text field e.g., Prefill_name=John Doe and what I am looking to do is prefill the current wordpress user. Assuming this is possible there must be a syntax that I am missing.

Chester_McLaugh
9 - Sun
9 - Sun

While using a shortcode plugin like the one below may help you get access to the data you want (current username and email) there will still be a potential problem of spaces or invalid HTML characters.

I think the best approach is to code your own custom shortcode that outputs exactly what you want using PHP. Then you can have logic, defaults, and properly encoded data.

If you want further help on this, reach out to me via https://www.codementor.io or my website https://chetmac.com

Ed_Furilla
5 - Automation Enthusiast
5 - Automation Enthusiast

Hi there, I had previously requested some guidance on prefilling an Airtable form. I am getting close to abandoning this approach and coming up with something different. Before I give up though i will see if there may be something seemingly simple that I may be missing. I tried the “shortcodes ultimate” and it works perfectly but I can’t figure out how to get it into the Airtable field.

The standalone shortcode is [su_user Name=“display_name”]

However placing it in an iframe is where i run into the issue. I assume the syntax is incorrect but i have tried evey combination i could think of to get it to work.

Note the your@email.address comes out the way it is shown here. However that doesn’t help me because i want to vary those fields based on the logged in user.

Anyway, thanks again for any help you can provide.
Ed

Chester_McLaugh
9 - Sun
9 - Sun

@Ed_Furilla Hit me up at https://www.codementor.io/chetmac and we can do a quick 15 minute screenshare. This will be almost trivial to get working for you.