
Set Limited Characters in an input field on Contact Form
Set Limited Characters in an input field on Contact Form. In this tutorial, I will demonstrate some Masked Input Type for Caldera Forms.
Mask Input In Caldera Forms
Mask Input extends the power of Single Line Text Field by adding a condition for a user’s input using a wildcard character. To enable this feature, you must tick Enable input mask and fill in Mask rule, e.g (aaa-99-999-a9-9*). Here is a list of rules:
- 9: numeric
- a: alphabetical
- *: alphanumeric
- [9 | a | *] : optional
- {int | * | +} : length
I made underneath form to show some examples:
paste these codes in functions.php on the theme file.
/**
* Set the Caldera Forms number field with the ID of fld_456’s maxlength to 20
*/
add_filter( ‘caldera_forms_field_attributes’, function( $attrs, $field, $form ){
if( ‘fld_8570647’ === $field[ ‘ID’ ] && ‘paragraph’ === Caldera_Forms_Field_Util::get_type( $field, $form ) ){
$attrs[ ‘maxlength’ ] = 20;
}
return $attrs;
}, 20, 3 );
//limit 9 chars
add_filter( ‘caldera_forms_field_attributes’, function( $attrs, $field, $form ){
if( ‘fld_5679963’ === $field[ ‘ID’ ] && ‘text’ === Caldera_Forms_Field_Util::get_type( $field, $form ) ){
$attrs[ ‘maxlength’ ] = 9;
}
return $attrs;
}, 20, 3 );
Read from github