Formidable Forms

Formidable Forms

  • Features
  • Pricing
  • Resources
    • Docs & Support
    • Blog
    • Community
  • Solutions
    • Web Applications
    • Calculators
    • Surveys
    • Directories
    • Payments
    • Contact forms
  • Login
  • Get Formidable Forms

frm_add_form_style_class

Last Updated: January 13, 2022

Knowledge Base → Extend Formidable Forms → Formidable Hooks - for Developers → Field Appearance → frm_add_form_style_class
Heads up!
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.

Each form style will have its own unique class name. When this form class name is added to the form, it will allow control for which styling settings the form uses.

Formidable Forms is the best WordPress Form Builder plugin. Get it for free!

This hook will allow you to select a different style than the one already selected in the form settings.

Usage

add_filter( 'frm_add_form_style_class', 'add_style_class', 1 );

Parameters

  • $class (string)
  • $args (array): Includes 'form'.

Examples

Replace with RTL style

This example checks the WPML language and uses styling settings for an RTL style instead of the regular style for your form.

add_filter( 'frm_add_form_style_class', 'add_style_class', 1 );
function add_style_class( $class ) {
  $lang = apply_filters( 'wpml_current_language', null );
  if ( $lang == 'ar' ) { // change ar to your language code
    remove_filter( 'frm_add_form_style_class', 'FrmStylesController::get_form_style_class', 10, 2 );
    $class .= 'frm_my_style_class frm_rtl'; // replace frm_my_style_class with your rtl style class
  }
  return $class;
}

Set Style in form shortcode

This example adds a use_style param to the form shortcode. If you'd like to display the form using a different Style than the form's default Style in a particular location, set the use_style param to the name of the different Style.

Use lowercase words with dashes in between, the way the Style appears in the Style class. There's no need to include "frm_style_" at the beginning, as this is added by the code example.

Usage:

Say you've created a Busy Bee Style that you want to use for your form on your home page but not on other pages. On the home page, your form shortcode could look like this:

[formidable id=100 use_style="busy-bee"]
add_filter( 'frm_add_form_style_class', 'frm_add_style_attribute_to_form_shortcode', 1 );
function frm_add_style_attribute_to_form_shortcode( $class ) {
	if ( ! isset( $_GET['use_style'] ) ) {
		return $class;
	}

	$new_style = $_GET['use_style'];
	$new_style = utf8_decode( urldecode( $new_style ) );
	$new_style = esc_html( $new_style );

	remove_filter( 'frm_add_form_style_class', 'FrmStylesController::get_form_style_class', 10, 2 );

	$class .= ' frm_style_' . $new_style . ' ';

	return $class;
}

Add custom class to a form

This code example adds a class "my_custom_class" to form ID 439. $form in this case is an array of form options that includes an array of fields.

add_filter( 'frm_add_form_style_class', 'add_style_class', 10, 3 );
function add_style_class( $class, $style, $args = array() ) {
	$target_form_id = 439; // change 439 to your form ID.
	if ( ! empty( $args['form'] ) && ! empty( $args['form']['fields'] ) ) {
		$field   = reset( $args['form']['fields'] );
		$form_id = (int) $field['form_id'];
		if ( $target_form_id === $form_id ) {
			$class .= ' my_custom_class'; // change my_custom_class to your class
		}
	}
	return $class;
}
  • Usage
  • Parameters
  • Examples
    • Replace with RTL style
    • Set Style in form shortcode
    • Add custom class to a form
Categories
×

Categories

  • Installation & Getting Started
  • Account Management
  • Forms
  • Entries
  • Views
  • Styles
  • Importing & Exporting
  • Add-Ons
  • Extend Formidable Forms

Using WordPress and want to get Formidable Forms for free?

Get Formidable Forms Lite Now

You do not have permission to view this form. Maybe you need to log in?

This article may contain affiliate links. Once in a while, we earn commissions from those links. But we only recommend products we like, with or without commissions.

Take on bigger projects Right Now

Get the tools you need to revolutionize your workflow and architect a masterpiece. Build the most advanced WordPress forms and actually use the data you collect in meaningful ways.

Get the most advanced WordPress form plugin and the only form builder with integrated Views.

Get Formidable Forms Now

Resources

  • Community
  • Affiliates
  • Contact
  • Free Online Form Builder

Top Features

  • Application Builder
  • Calculator Forms
  • Surveys & Polls
  • Quiz Maker
  • Form Templates
  • Application Templates
  • Directories
  • Donation Plugin

Company

  • About Us
  • Giving Back
  • Careers
  • Newsletter
  • WP Tasty
  • Nutrifox

Copyright © 2023 Strategy11, LLC. Formidable FormsĀ® is a registered trademark Strategy11, LLC.
Privacy Policy | Terms of Service | Sitemap

Join 300,000+ using Formidable Forms to create form-focused solutions fast. Get Started See User Reviews