Forked from Shelob9/caldera_forms_field_attributes-add-attr.php
Last active
September 19, 2019 10:54
-
-
Save New0/f2d7ddaac4e821fbee917ec7c244ece0 to your computer and use it in GitHub Desktop.
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/
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 paragraph 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 ); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment