PLEASE NOTE: These forums are no longer utilized and are provided as an archive for informational purposes only. All support issues will be handled via email using our support ticket system. For more detailed information on this change, please see this blog post.

Max Characters in Title

  1. selym
    Member

    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

    Posted 7 years ago on Thursday October 20, 2011 | Permalink
  2. 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.

    Posted 7 years ago on Thursday October 20, 2011 | Permalink
  3. selym
    Member

    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

    Posted 7 years ago on Friday October 21, 2011 | Permalink
  4. Which of my suggestions did you like best? I will help you implement the one you would like to try.

    Posted 7 years ago on Friday October 21, 2011 | Permalink
  5. 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.

    Posted 7 years ago on Saturday November 19, 2011 | Permalink
  6. Cirfzen
    Member

    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.

    Posted 7 years ago on Friday May 18, 2012 | Permalink
  7. Cirfzen
    Member

    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..

    Posted 7 years ago on Friday May 18, 2012 | Permalink
  8. Nicolap
    Member

    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.

    Posted 6 years ago on Monday October 1, 2012 | Permalink
  9. David Peralty
    Administrator

    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.

    Posted 6 years ago on Monday October 1, 2012 | Permalink
  10. John
    Member

    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?

    Posted 6 years ago on Tuesday October 2, 2012 | Permalink
  11. @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.

    Posted 6 years ago on Tuesday October 2, 2012 | Permalink
  12. Just for the record, I would love the ability to do this on the form posting fields also.

    Posted 6 years ago on Sunday April 21, 2013 | Permalink