I realize there's a way to set a maximum character count in single line and paragraph text areas, but is there a way to do this for titles? I'd like to prevent users from submitting really long post titles.
Thanks,
Selym
I realize there's a way to set a maximum character count in single line and paragraph text areas, but is there a way to do this for titles? I'd like to prevent users from submitting really long post titles.
Thanks,
Selym
How about filtering the title after the form is submitting, and truncating it at your maximum character count? Or, hiding the long title with CSS in your theme? Or, performing custom validation on it, and returning an error when the title is too long, allowing the visitor to submit a shorter title?
I don't know if there's an easy way to do client side validation of the max characters of a simple text field, rather than a textarea.
Thanks for your suggestions Chris. I don't understand how to implement any of your suggestions without some research, but I'm trying. I'm currently reading and attempting to figure out what the heck is being discussed here:
http://www.gravityhelp.com/documentation/page/Using_the_Gravity_Forms_%22gform_validation%22_Hook
GravityForms certainly appears to have a ton of options and flexibility, but when you're not a programmer, it sure starts to feel a lot less flexible.
Thanks,
Selym
Which of my suggestions did you like best? I will help you implement the one you would like to try.
I would be interested in this as well. It is weird that it's not implemented on the Title field as well as most other fields have it...
As for the suggestions, how would you go about doing the custom validation? The other suggestions are not really an option as truncating the title without informing the user seems to me a really bad idea.
I have the same problem and would be happy to find a solution.
Maybe it can be done with the filter "gform_field_content".
But the example provided by Gravity Forms documentation is a bit to complex for me to understand.
So someone with more knowledge in this filters and hooks, please enlighten us.
Tried a validation solution that works:
<?php
/* VALIDATE title for max char of 30, form have id 1 and title field is number 4 */
add_filter("gform_field_validation_1_4", "custom_validation", 10, 4);
function custom_validation($result, $value, $form, $field){
if($result["is_valid"] && strlen($value) > 30){
$result["is_valid"] = false;
$result["message"] = "Maximum of 30 characters is allowed!";
}
return $result;
}
?>
But the best solution would be to have a Max character choice in the Form editor like the rest of the text fields..
I would like this feature as well. I don't understand why there can't be a character limit for Titles like there is for Posts.
Hi Nicolap, lots of people have found workarounds, and it isn't a widely needed feature, so we haven't ever implemented it. We try to be careful about adding features so that people don't feel overwhelmed by the number of options on each field. Imagine if we had every option available for every field. It would take hours to potentially build a single form.
I too would like to implement a max character count for post titles on my forms.
To David (or anyone else that may know) — I am interested in trying the validation solution that Cirfzen provided above. However, where do I insert that code?
@John, that code will go in your theme's functions.php file. You will have to customize the form ID and field ID before the code will work for you.
Just for the record, I would love the ability to do this on the form posting fields also.