Mar 25, 2022: Migrated to Snippet Library.
May 30, 2014: Added support for requiring a maximum character count as well.
Have you ever received a generic comment or question in a form submission and wondered if there was a way to discourage this type of response? We’ve whipped up a little snippet that you can use to encourage a more descriptive comment from users submitting your forms.
How do I get started?
- This will work with even Gravity Forms v1.0 but that’s no excuse not to be running the latest version.
- Copy and paste the snippet into your theme’s functions.php file.
- Once you have installed the snippet, you just need to configure the snippet for your Gravity form. See the usage instructions below.
new GW_Minimum_Characters( array( 'form_id' => 123, 'field_id' => 4, 'min_chars' => 3, 'max_chars' => 5, 'min_validation_message' => __( 'Oops! You need to enter at least %s characters.' ), 'max_validation_message' => __( 'Oops! You can only enter %s characters.' ), ) );
min_chars parameters are required. Incorrect values will cause the snippet to fail silently; no error message will be displayed.
- form_id (integer) (required) The form ID of your form.
- field_id (integer) (required) The field ID of the field that you would like to enable a minimum character limit.
- min_chars (integer) (required) The minimum character limit that you would like to apply to the field.
- validation_message (string) (optional) The validation message that you would like to display to the user when the minimum character limit is not reached.
- min_validation_message (string) (optional)
The validation message that you would like to display to the user when the minimum character limit is not reached. Added to better differentiate between the
- max_validation_message (string) (optional) The validation message that you would like to display to the user when the maxiumum character limit is exceeded.
Can I add this to more than one field per form?
You sure can! You can add this to as many fields on as many forms as you want. Simply copy and paste the configuration code listed above and update the values for your new form and field.
If you use it and like it, let us know. We’d love to hear the different reasons how you found this code useful!