Skip Navigation

[Resolved] Limit the Number of Characters in a Text Field in a content submission form

This support ticket is created 6 years, 1 month 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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+00:00)

This topic contains 4 replies, has 2 voices.

Last updated by Nicola Inwood 6 years, 1 month ago.

Assisted by: Nigel.

Author
Posts
#1124860

Tell us what you are trying to do?

I have text areas in one of our content submission forms and want to control how many characters are submitted in that area. What is the easiest way to do this?

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

#1125225

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

Hi Nicola

You can add a little snippet of JavaScript to your form to set the maxcharacters attribute on the textarea(s).

When editing your form you can add the following to the JS editor section:

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

You just need to edit the number of characters (currently 20).

#1125537

Nigel

Thanks you for this. So nice to have such a rapid response.

Is there also the same option for the post_excerpt area in the post form?

#1125890

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+00:00)

The name of the post excerpt textarea is "post_excerpt" so it's missed by the selector in the above code, so you just need to update it to add it separately, like so:

( function( $ ) {
    $( document ).ready( function(){
        $('textarea[name^="wpcf-"]').attr('maxlength', 20);
        $('textarea[name="post_excerpt"]').attr('maxlength', 20);
    });
})( jQuery );
#1126448

My issue is resolved now. Thank you!