Skip Navigation

[Resolved] Limit number of characters in multi-line text field in form

This thread is resolved. Here is a description of the problem and solution.

Problem:

How to limit the characters of a multiline input form item.

Solution:

Please add ttehJavascript code below to the form JS Editor section:

jQuery(function() {
    jQuery('textarea[name="wpcf-placeholder"]').attr('maxlength', '20');
});

Make sure to replace placeholder with the slug of the multiline field.

This support ticket is created 2 years, 9 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 6.93 hours from now. Thank you for your understanding.

This topic contains 4 replies, has 2 voices.

Last updated by janeC-2 2 years, 9 months ago.

Assisted by: Christopher Amirian.

Author
Posts
#2286477

Hi,
For my form I would like to limit the number of characters for one of the multi-line text fields.
Can you please direct me to where I can find out how to do this?
I followed some of the support threads but the information is a bit unclear.

#2286857

Christopher Amirian
Supporter

Languages: English (English )

Hi there,

It might be possible to do that with Javascript, but I will need a link to your form and know which text field you talk about to be able to check and see if I can give proper code for that.

Thanks.

#2287533
toolset form help.jpg
toolset form help 2.jpg

Form url: hidden link
Field: Artist Statement
Slug: artwork-artist-statement
CPT: Entries

#2287711

Christopher Amirian
Supporter

Languages: English (English )

Screen Shot 2022-02-09 at 15.04.27.png

Hi there,

Thank you for the link. Please go to the Form JS Editor and add the code below:

jQuery(function() {
	jQuery('textarea[name="wpcf-artwork-artist-statement"]').attr('maxlength', '20');
});

The code above makes use of the standard HTML maxlength attribute. But please consider that it is a character based number, so you need to add the number of the character limit and not the Word limit.

As an example you can change 20 to 30 to force a 30 character limitation for the textarea in question.

Thank you.

#2288185

My issue is resolved now. Thank you!