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.

Tagit - restricting the number of tags entered

  1. Gavin Webb
    Member

    Hi - I've created a Single Line Text field, and checked the Save To Taxonomy option (using the Gravity Forms + Custom Post Types plugin) and the Enable enhanced UI. It all seems to work in that the tags entered into the field become a taxonomy term - fantasitic :)

    However, how can I restrict the number of terms entered into the field to say three?

    Thanks and all the best. Gavin.

    Posted 7 years ago on Wednesday October 3, 2012 | Permalink
  2. If you want to restrict the input in a form field, you can do it on the front end with jQuery and prevent more than 2 spaces from being entered:

    http://stackoverflow.com/questions/8618247/how-to-stop-writing-in-textbox-by-using-javascript

    Or you can use the gform_validation hook to check the text which is entered and strip out any words over 3, or return an error and tell the visitor they need to enter fewer tags.

    http://www.gravityhelp.com/documentation/page/Gform_validation

    Posted 7 years ago on Wednesday October 3, 2012 | Permalink
  3. Gavin Webb
    Member

    Thanks Chris - I'm thinking I'll go down the hooks route, however, I haven't a clue where to start. I've spent some time reading through the Gform validation information, as well as the associated links and really am lost :)

    As for the javascript bit ??? Learning this is on my list of to dos :)

    Thanks. Gavin.

    Posted 7 years ago on Thursday October 4, 2012 | Permalink
  4. Using gform_validation is a little bit confusing, but if you start with one of the examples and don't change any of the logic or functionality, just customize it for your form and form fields, I think you will get it working. Then, you can change the function which parses the text field and then returns an error if more than 3 words are entered.

    If you wanted to be blunt about it, you could use the gform_pre_submission filter to just strip out any word after the third, with no message to the visitor that you modified their input. You could always tell them afterward, in the confirmation message, that what they entered is too long and you shortened it.

    Posted 7 years ago on Thursday October 4, 2012 | Permalink