This article contains PHP code and is intended for developers. We offer this code as a courtesy, but don't provide support for code customizations or 3rd party development.
Use the frm_show_it hook to customize the value displayed in a Dynamic List field (previously called a Dynamic - Show It field).
Upgrade your WordPress site with powerful, flexible forms.
Usage
add_filter('frm_show_it', 'custom_dynamic_list_display', 10, 3);
function custom_dynamic_list_display( $html, $value, $args )This filter runs when a Dynamic List field loads its value. That happens after an entry is selected in the Dynamic field the List field depends on. See how to dynamically display values from a selected entry.
Since Formidable Forms Pro 7.0, the HTML this filter returns is checked against Formidable's allowed HTML list:
- Links, images, and basic markup such as strong, h2, code, blockquote, and button are kept.
- Tags that aren't on the list, such as script, iframe, style, and table, are removed. The text inside them still shows on the page as plain text.
- Event attributes such as onclick and data- attributes are removed. Style attributes are kept only on div, span, i, and svg tags.
The field value is also checked before this filter runs. Unless an administrator or a user who can edit entries created or last edited the entry, only basic formatting stays in $html. That means bold, italic, paragraphs, line breaks, and lists. Images from File Upload fields are kept.
From Idea to Reality in Minutes. Build Powerful Forms, Dashboards, Apps and More.
Formidable Forms makes advanced site building simple. Launch forms, directories, dashboards, and custom WordPress apps faster than ever before.
Parameters
- $html (string): the full HTML to be displayed
- $value (mixed): the value to be displayed
- $args (array): additional attributes including the entry ID and the linked field object. The keys are
field(the linked field object),value(the saved value) andentry_id.
Examples
Customize a Dynamic List field
Use the code below to customize the HTML displayed in a Dynamic List field.
add_filter('frm_show_it', 'custom_dynamic_list_display', 10, 3);
function custom_dynamic_list_display( $html, $value, $args ) {
if ( $args['field']->id == 30 ) { //change 30 to the id of the linked field ID
// Customize displayed value here
}
return $html;
}
Show full image instead of thumbnail
Use the code below to show the full selected image in a Dynamic List field, instead of just the thumbnail.
add_filter( 'frm_show_it', 'custom_frm_show_it', 10, 3 );
function custom_frm_show_it( $html, $value, $args ) {
if ( $args['field']->id == 30 ) { //change 30 to the id of the upload field in the other form
$media_ids = explode( ', ', $args['value'] );
$html = "<div class='frm_show_it'>";
$new_value = '';
foreach ( $media_ids as $media_id ) {
$image = FrmProFieldsHelper::get_display_value( $media_id, $args['field'], array(
'show_image' => true,
'size' => 'full'
) );
$new_value .= $image;
}
$html .= "<p>" . $new_value . "</p>";
$html .= '</div>';
}
return $html;
}
Show option label
If you are pulling data from a field with separate values, Dynamic List fields show the option label. The first line of the code below uses the frm_should_dynamic_field_use_option_label filter to show saved values in all Dynamic fields instead. The rest of the code then shows the option label in a Dynamic List field. Just replace 485 with the ID of the field that your Dynamic List field is retrieving its value from.
add_filter( 'frm_should_dynamic_field_use_option_label', '__return_false' ); //show saved values instead of labels in Dynamic fields
add_filter('frm_show_it', 'dynamic_list_show_option_label', 10, 3);
function dynamic_list_show_option_label( $html, $value, $args ){
if ( $args['field']->id == 485 && $args['field']->field_options['separate_value'] ) {
foreach ( $args['field']->options as $option ) {
if ( is_array( $option ) && isset( $option['value'] ) && $option['value'] == $value ) {
$html = str_replace( '>' . $value . '<', '>' . $option['label'] . '<', $html ); //replace only the displayed text
break;
}
}
}
return $html;
}
Allow a table in the returned HTML
Use the code below to keep a table in the HTML your frm_show_it function returns. Each tag gets an array of the attributes it may keep. Add the child tags too: with table alone, the tbody, tr, and td tags are still removed. The table itself must come from the saved field value or from your own frm_show_it function. This code only stops it from being removed.
add_filter( 'frm_striphtml_allowed_tags', 'my_allow_table_tags' );
function my_allow_table_tags( $allowed ) {
$allowed['table'] = array( 'class' => true );
$allowed['tbody'] = array();
$allowed['tr'] = array();
$allowed['td'] = array( 'colspan' => true );
return $allowed;
}
This doesn't change the check on the field value. If an administrator or a user who can edit entries didn't create or last edit the entry, its own table is still removed.