The Community forums are being phased out in favor of a new Slack group.
Add your email address below to get an invitation to join the community slack group
Get ID with KEY OR using KEYs instead of IDs for fields/forms OR just get
Hello,
I just wrote a simple function to get IDs of Form or Field, by using its KEYs.
I need this for my MU installation. Perhaps someone will need it too.
I found some posts and answers so I've took some of them and create this function.
It's really usefulĀ for MU installs.
/** * Function to get ID of the Formidable form or field from form/field key * Source - https://formidableforms.com/help-desk/keys-vs-ids/ (note that there is a typo in the example code - last ")" was missed) * * @uses globals $frmdb, $wpdb * @param $form_or_field - string with two possible values: 'form' or 'field' * @param $key - string with key of the Formidable form or field * @return $id_from_key - numeric ID **/ function get_id_from_key_frm ( $form_or_field, $key ) { global $frmdb, $wpdb; // Getting form ID using form_key if ( $form_or_field == 'form' && $key != '' ) { $id_from_key = $wpdb->get_var($wpdb->prepare("SELECT id from $frmdb->forms WHERE form_key = %s", $key)); // Getting field ID using field_key } elseif ( $form_or_field == 'field' && $key != '' ) { $id_from_key = $wpdb->get_var($wpdb->prepare("SELECT id from $frmdb->fields WHERE field_key=%s", $key)); } if (is_numeric($id_from_key)){ return $id_from_key; } }
Then you can use it in you theme or functions.php file like this:
$form_id = get_id_from_key_frm ( 'form', 'xxxxx' ); // change 'xxxxx' to the key of your form $field_id = get_id_from_key_frm ( 'field', 'xxxxx' ); // change 'xxxxx' to the key of the field
December 5, 2014 at 9:36 am
Thanks for sharing!
Discussion closed.