Last active
June 10, 2022 11:30
-
-
Save stephywells/66498afd902523b27501 to your computer and use it in GitHub Desktop.
Formidable Shortcodes
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 | |
//* Do NOT include the opening php tag | |
// Add this to your theme functions.php or a new plugin | |
// to enable a shortcode to return a list of entry ids with completed payments | |
// 1. Create a view to show only the entries with completed payments | |
// 2. Go down to the "advanced settings" section of your view, and add a filter: | |
// Entry id is equal to [frm_completed_entries form_id=5] | |
// 3. Replace 5 with the id of your form. | |
add_shortcode('frm_completed_entries', 'frm_completed_entries'); | |
function frm_completed_entries($atts){ | |
extract ( shortcode_atts(array('form_id' => false), $atts)) ; | |
if ( !$form_id) { | |
//if no form id is specified, then don't return anything | |
return ''; | |
} | |
global $wpdb; | |
$completed = $wpdb->get_col($wpdb->prepare("SELECT p.item_id FROM {$wpdb->prefix}frm_payments p LEFT JOIN {$wpdb->prefix}frm_items i ON (i.id=p.item_id) WHERE completed = %d and i.form_id=%d", 1, (int) $form_id)); | |
// return a comma separated list of entry ids | |
return implode(',', $completed); | |
} |
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 | |
//* Do NOT include the opening php tag | |
// Add this to your theme functions.php or a new plugin | |
// to enable a shortcode to return the form page number dynamically | |
// 1. Add an HTML field to your form wherever you would like a page number to show | |
// 2. Insert a shortcode in your HMTL field: [frm_page_num form_id=5 page_id=50] | |
// 3. Replace 5 with the id of your form, and 50 with the id of the page field | |
// proceeding your shortcode. | |
// Since there is no page break for the first page, your shortcode will look | |
// like this: [frm_page_num form_id=5] | |
add_shortcode('frm_page_num', 'frm_page_num'); | |
function frm_page_num($atts) { | |
extract(shortcode_atts(array( | |
'form_id' => isset($_POST['form_id']) ? $_POST['form_id'] : false, | |
'page_id' => false | |
), $atts)); | |
if ( !$form_id || !is_callable('FrmProFieldsHelper::is_field_hidden') ) { | |
// don't continue if Formidable is not installed | |
return; | |
} | |
if ( !$page_id ) { | |
return 1; | |
} | |
$frm_field = new FrmField(); | |
$page_breaks = $frm_field->getAll( array('fi.form_id' => (int) $form_id, 'type' => 'break'), 'field_order' ); | |
$num = 1; | |
foreach ( $page_breaks as $break ) { | |
if ( $page_id == $break->id ) { | |
// we've reached the current page | |
$num++; | |
break; | |
} | |
if ( !FrmProFieldsHelper::is_field_hidden($break, $_POST) ) { | |
$num++; | |
} | |
unset($break); | |
} | |
return $num; | |
} |
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 | |
//* Do NOT include the opening php tag | |
// Add this to your theme functions.php or a new plugin | |
// to enable a shortcode to return a list of options in a field | |
// with the most chosen value marked with the percentage of votes | |
// and one "(winner)" | |
//1. Add a dropdown or radio field and collect your survey results. | |
//2. Insert this shortcode on your page. [frm-winner id=25 winner="(winner)"] | |
//3. Change 25 to the id of your field. | |
add_shortcode('frm-winner', 'frm_stats_winner'); | |
function frm_stats_winner($atts){ | |
$defaults = array( | |
'id' => false, 'user_id' => false, 'sep' => ', ', | |
'winner' => '(winner)' | |
); | |
extract(shortcode_atts($defaults, $atts)); | |
if (!$id) return; | |
global $frm_form, $frm_field; | |
$form = $frm_form->getOne($id); | |
$fields = $frm_field->getAll(array('fi.form_id' => $form->id), 'field_order'); | |
$type = 'count'; | |
$content = '<ol>'; | |
foreach ( $fields as $field ) { | |
if ( empty($field->options) ) { | |
continue; | |
} | |
$content .= '<li>'. $field->name .'<ol style="list-style-type:lower-alpha">'; | |
$field_values = array(); | |
foreach ( $field->options as $opt ) { | |
if ( is_array($opt) ) { | |
$field_val = isset($opt['label']) ? $opt['label'] : reset($opt); | |
} else { | |
$field_val = $opt; | |
} | |
if ( $field_val == '' ) { | |
continue; | |
} | |
$field_values[$field_val] = FrmProStatisticsController::stats_shortcode( array( | |
'id' => $field->id, 'type' => $type, | |
'value' => $field_val, 'user_id' => $user_id | |
) ); | |
unset($opt); | |
} | |
$max = max($field_values); | |
foreach ( $field_values as $val => $stat ) { | |
$wins = $stat ? ($stat == $max) : false; | |
$content .= '<li'. ($wins ? ' class="frm_winner"' : '') .'>'. $val . ($wins ? ' '. $winner : '') .'</li>'; | |
unset($val); | |
} | |
$content .= '</ol></li>'; | |
} | |
$content .= '</ol>'; | |
return $content; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Formidable hooks https://docs.hookmax.com/plugin/formidable/
**Formidable forms database: **. https://wpdebuglog.com/downloads/formidable-forms-mysql/