WordPress user data prefill

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.

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

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

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

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.

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…

@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:

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

Working Example:

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.

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

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

@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.

1 Like