Last active
November 17, 2017 14:50
-
-
Save New0/6f005622dd8cc02eaa72acd190decfa0 to your computer and use it in GitHub Desktop.
Set a pattern for min and max length of fields, combined with the required field option.
This file contains 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 | |
//Use caldera_forms_field_attributes filter hook | |
add_filter( 'caldera_forms_field_attributes', function( $attrs, $field, $form ){ | |
//REPLACE fld_******* BY YOUR OWN FIELD IDs | |
//Min and max 5 | |
if( 'fld_4009904' === $field[ 'ID' ] ) { | |
$attrs[ 'pattern' ] = ".{5,5}"; | |
} | |
//Min and max 10 | |
if( 'fld_*******' === $field[ 'ID' ] ) { | |
$attrs[ 'pattern' ] = ".{10,10}"; | |
} | |
return $attrs; | |
}, 20, 3 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment