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.
This hook allows you to add classes to the <form> tag for all forms or only those that are specified. This code can be used to add a background color to your forms.
Usage
add_action('frm_form_classes', 'frm_form_classes'); function frm_form_classes($form)
Parameters
- $form (object)
Examples
Add a class to a form
add_action( 'frm_form_classes', 'frm_form_classes' );
function frm_form_classes( $form ) {
if ( $form->id == 25 ) { //Change 25 to the ID of your form
echo 'new_class';
}
}
Add a class to all forms
add_action( 'frm_form_classes', 'frm_form_classes' );
function frm_form_classes( $form ) {
echo 'new_class';
}
Add class to form based on param
You can use this code example to add a class to your form in some locations on your site but not others. This class can be used to add different styling to the form.
Use the add_class param to set the value of the new class. You can add the add_class param to your form shortcode or set it using frm-set-get.
Usage
- As a param in the form shortcode: [formidable id="1245" add_class="rose"]
- Using frm-set-get:
[frm-set-get add_class="rose"]
[formidable id="1245"]
Or add a Formidable forms block to display the form.
Note: frm-set-get needs to be before the form on the page.
add_action( 'frm_form_classes', 'frm_add_new_class' );
function frm_add_new_class( $form ) {
if ( ! isset( $_GET['add_class'] ) ) {
return;
}
$new_class = $_GET['add_class'];
$new_class = utf8_decode( urldecode( $new_class ) );
echo esc_html( $new_class );
}