Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save Shelob9/3eed7e9d43c39655dd65e782daefbf82 to your computer and use it in GitHub Desktop.
Save Shelob9/3eed7e9d43c39655dd65e782daefbf82 to your computer and use it in GitHub Desktop.
Change maxlength for Caldera Forms text and text input or max for number fields See: https://calderaforms.com/doc/caldera_forms_field_attributes/
<?php
/**
* Set a max length attribute for all paragraph fields in Caldera Forms
*/
add_filter( 'caldera_forms_field_attributes-paragraph', function( $attrs ){
$attrs[ 'maxlength' ] = 255;
return $attrs;
});
<?php
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field, $form ){
$type = Caldera_Forms_Field_Util::get_type( $field, $form );
if( 'text' == $type ){
$attrs[ 'maxlength' ] = 255;
}elseif( 'paragraph' == $type ){
$attrs[ 'maxlength' ] = 512;
}elseif( 'number' == $type ){
$attrs[ 'max' ] = 42;
}
return $attrs;
}, 10, 3 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment