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 custom parameters in the [formidable] shortcode.
Usage
add_action('formidable_shortcode_atts', 'formidable_shortcode_atts', 20, 2); function formidable_shortcode_atts( $atts, $all_atts )
Parameters
- $atts (array) The standard options in the formidable shortcode
- $all_atts (array) All attributes included in the shortcode
Examples
Disable readonly for Admins
Mark the fields read only in your field settings like normal, and then conditionally disable it with this function. Include readonly='administrator' in your [ formidable] shortcode, and use this example to process it.
add_action('formidable_shortcode_atts', 'frm_admin_readonly', 20, 2);
function frm_admin_readonly( $atts, $all_atts ) {
if ( $atts['readonly'] == 'administrator' ) {
global $frm_vars;
if ( current_user_can('administrator') ) {
$frm_vars['readonly'] = 'disabled';
} else {
$frm_vars['readonly'] = false;
}
}
}
Change style template based on parameter
If you have the same form published in multiple locations and you want to have different styles, you can use this example. When publishing the form, use the shortcode:
[formidable id=x form_style="formidable-style-7"]
Replace "formidable-style-7" with the style name, which you can find for the particular style under Formidable > Styles next to the "Style Name".
add_action( 'formidable_shortcode_atts', 'maybe_change_style_class', 10, 2 );
function maybe_change_style_class( $shortcode_atts, $atts ) {
if ( isset( $atts['form_style'] ) ) {
global $frm_atts;
$frm_atts['switch_style'] = $atts['form_style'];
add_filter( 'frm_add_form_style_class', 'change_style_class', 20 );
}
}
function change_style_class( $class ) {
global $frm_atts;
if ( isset( $frm_atts['switch_style'] ) ) {
$new_class = $frm_atts['switch_style'];
$class = 'with_frm_style frm_style_' . $new_class;
//reset for other forms
unset( $frm_atts['switch_style'] );
remove_filter( 'frm_add_form_style_class', 'change_style_class', 20 );
}
return $class;
}