Created
June 8, 2019 17:17
-
-
Save chetmac/e55899bd14dcf803846ad524c538c248 to your computer and use it in GitHub Desktop.
Wordpress Shortcode for embedding form with prefilled fields
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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