Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Examples of how to use the Caldera Forms filter caldera_forms_field_attributes to modify Caldera Forms input elements. See: https://calderaforms.com/doc/caldera_forms_field_attributes/
<?php
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field, $form ){
if( 'button' === Caldera_Forms_Field_Util::get_type( $field, $form ) ){
$attrs[ 'data-form-id' ] = $form[ 'ID' ];
}
return $attrs;
}, 20, 3 );
<?php
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field, $form ){
if( 'text' === Caldera_Forms_Field_Util::get_type( $field, $form ) ){
$attrs[ 'class' ] .= ' my-special-class';
}
return $attrs;
}, 20, 3 );
<?php
/**
* Set all Caldera Forms number fields' max value to 75
*/
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field, $form ){
if( 'number' === Caldera_Forms_Field_Util::get_type( $field, $form ) ){
$attrs[ 'max' ] = 75;
}
return $attrs;
}, 20, 3 );
/**
* Set the Caldera Forms number field with the ID of fld_456's max value to 75
*/
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field, $form ){
if( 'fld_456' === $field[ 'ID' ] && 'number' === Caldera_Forms_Field_Util::get_type( $field, $form ) ){
$attrs[ 'max' ] = 75;
}
return $attrs;
}, 20, 3 );
/**
* Set all Caldera Forms number fields that are in the form with the ID cf_12324's max value to 75
*/
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field, $form ){
if( 'cf_12324' === $form[ 'ID' ] && 'number' === Caldera_Forms_Field_Util::get_type( $field, $form ) ){
$attrs[ 'max' ] = 75;
}
return $attrs;
}, 20, 3 );
<?php
/**
* Set all Caldera Forms paragraph fields' maxlength to 75
*/
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field, $form ){
if( 'paragraph' === Caldera_Forms_Field_Util::get_type( $field, $form ) ){
$attrs[ 'maxlength' ] = 75;
}
return $attrs;
}, 20, 3 );
/**
* Set the Caldera Forms number field with the ID of fld_456's maxlength to 75
*/
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field, $form ){
if( 'fld_456' === $field[ 'ID' ] && 'paragraph' === Caldera_Forms_Field_Util::get_type( $field, $form ) ){
$attrs[ 'maxlength' ] = 75;
}
return $attrs;
}, 20, 3 );
/**
* Set all Caldera Forms paragraph fields that are in the form with the ID cf_12324's maxlength to 75
*/
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field, $form ){
if( 'cf_12324' === $form[ 'ID' ] && 'paragraph' === Caldera_Forms_Field_Util::get_type( $field, $form ) ){
$attrs[ 'maxlength' ] = 75;
}
return $attrs;
}, 20, 3 );
<?php
//Disable saturday and sunday as options for date picker fields
//see: http://bootstrap-datepicker.readthedocs.io/en/latest/options.html?highlight=disable#daysofweekdisabled
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field, $form ){
if( 'date_picker' === Caldera_Forms_Field_Util::get_type( $field, $form ) ){
$attrs[ 'data-date-days-of-week-disabled' ] = '06';
}
return $attrs;
}, 20, 3 );
@atadar

This comment has been minimized.

Copy link

commented Oct 25, 2018

Hi, can you please explain what does 20, 3 in the last raw means?

@chris-chalmers

This comment has been minimized.

Copy link

commented Oct 27, 2018

@atadar they are priority and # of accepted arguments. see https://developer.wordpress.org/reference/functions/add_filter/

@chris-chalmers

This comment has been minimized.

Copy link

commented Oct 27, 2018

@Shelob9 I'm trying to add an attribute to inputs of type=ratio. I see that radio and checkboxes are still not supported. Any Ideas of what I could do in the mean time? Thanks in advance!

@nheveres

This comment has been minimized.

Copy link

commented Feb 9, 2019

Is it possible to determine for a certain 'date_picker' the condition to work and what must i fill?

@StonehengeCreations

This comment has been minimized.

Copy link

commented Oct 3, 2019

It's simple to disable days of the week, but how do I disable specific dates?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.