Skip to content

Instantly share code, notes, and snippets.

@ms-studio
Last active October 7, 2018 17:15
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ms-studio/aa8c7a99618d447bb0518ad15225794d to your computer and use it in GitHub Desktop.
Save ms-studio/aa8c7a99618d447bb0518ad15225794d to your computer and use it in GitHub Desktop.
Shortcode for the Formidable WordPress plugin, that returns the name of the current form (based on the entry ID).
<?php
/*
* Form Name Shortcode
* For usage in confirmation email
* Returns name of current form
* Use the shortcode like this: [frm-form-name id=[id]]
* The [id] parameter will produce the ID of current entry
* See https://formidableforms.com/help-desk/using-form_name-shortcode-in-email-notification/
*/
function my_frm_name_shortcode( $atts ) {
global $wpdb;
$a = shortcode_atts( array(
'id' => '',
), $atts );
if (!empty($a['id'])) {
// get the Form ID, based on Entry ID
$form_id = $wpdb->get_row( $wpdb->prepare(
"
SELECT form_id
FROM ". $wpdb->prefix ."frm_items
WHERE id = %d
",
$a['id'])
);
// get the Form name, based on Form ID
$form_name = $wpdb->get_row( $wpdb->prepare(
"
SELECT name
FROM ". $wpdb->prefix ."frm_forms
WHERE id = %d
",
$form_id->form_id )
);
return $form_name->name;
}
}
add_shortcode( 'frm-form-name', 'my_frm_name_shortcode' );
@RonR-WebDesign
Copy link

Thanks for this... works perfectly!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment