Skip to content

Instantly share code, notes, and snippets.

@chetmac
Created June 8, 2019 17:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chetmac/e55899bd14dcf803846ad524c538c248 to your computer and use it in GitHub Desktop.
Save chetmac/e55899bd14dcf803846ad524c538c248 to your computer and use it in GitHub Desktop.
Wordpress Shortcode for embedding form with prefilled fields
<?php
// [airtableform form_id="shr1St9pPOAptb7r8"]
function airtableform_func( $atts ) {
$a = shortcode_atts( array(
'form_id' => '',
'width' => '100%',
'height' => '533',
'color' => 'red',
), $atts );
$current_user = wp_get_current_user();
$prefill_string = "";
if ( $current_user->exists() ) {
$prefill = [
"Name" => $current_user->user_login,
"Notes" => $current_user->user_email
];
foreach($prefill as $key => $value){
$prefill_string .= "&prefill_" . rawurlencode($key) . "=" . rawurlencode($value);
}
}
return '<iframe class="airtable-embed" src="https://airtable.com/embed/' . $a["form_id"] . '?backgroundColor=' . $a["color"] . $prefill_string . '" frameborder="0" onmousewheel="" width="' . $a["width"] . '" height="' . $a["height"] . '" style="background: transparent; border: 1px solid #ccc;"></iframe>';
}
add_shortcode( 'airtableform', 'airtableform_func' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment