WordPress.org

Ready to get started?Download WordPress

Forums

Contact Form 7
Word Count Restriction (11 posts)

  1. jpretorious
    Member
    Posted 1 year ago #

    Looking to restrict word count on a text area. How can I do this?

    I submitted this question yesterday but do not see it on the list.

    Thank You,
    Justine

    http://wordpress.org/extend/plugins/contact-form-7/

  2. GodEmperor
    Member
    Posted 1 year ago #

    I'm also in a situation where I'd like to know if this is possible.

    I'm still using Contact Form 7 version 3.3.1 because it's the latest compatible version with Contact Form 7 Textarea Wordcount, which is no longer in development.

    has this feature been added to the newer versions of Contact Form 7?

    IIRC, 3.3.1 CF7 only supported text box character limits, but nothing for text areas.

    Thanks!!

  3. jpretorious
    Member
    Posted 1 year ago #

    I wished I had read your post before I upgraded the Contact Form 7 plugin :(

    I REALLY need get an answer on this and the Contact Form 7 Textarea Wordcount plugin broke my website when I activated it.

    I haven't found an answer yet for wordcount restriction. Still looking.

    Justine

  4. GodEmperor
    Member
    Posted 1 year ago #

    what you can do is go grab 3.3.1 CF7, and just continue with that onward until they add wordcount support.

    http://wordpress.org/extend/plugins/contact-form-7/download/

  5. MickeyRoush
    Member
    Posted 1 year ago #

    You can limit it to characters with something like this below. Just add it to your theme's functions.php and change the 400 to whatever you need.

    // Limit Contact Form 7's textarea/message field to 400 characters
    add_filter( 'wpcf7_validate_textarea', 'character_length_validation_filter', 11, 2 );
    add_filter( 'wpcf7_validate_textarea*', 'character_length_validation_filter', 11, 2 );
    
    function character_length_validation_filter( $result, $tag ) {
    	$name = $tag['name'];
    
    	if ( ! $result['valid'] )
    		return $result;
    
    	if ( 400 < strlen( $_POST[$name] ) ) {
    		$result['valid'] = false;
    		$result['reason'][$name] = "You have exceeded the 400 character limit.";
    	}
    
    	return $result;
    }
  6. jpretorious
    Member
    Posted 1 year ago #

    I actually need to limit the textarea for more than just one textarea. I have 3 and 2 of them are 250 and the last textarea needs to be 400. How would I do this?

    Thank You,
    Justine

  7. chaoti
    Member
    Posted 1 year ago #

    @jpretorious Hi Justine, did you find a solution? I would like to know it, too... :)

  8. jpretorious
    Member
    Posted 1 year ago #

    @chaoti I was able to use Contact Form 7 Textarea Wordcount plugin up until this week when I accidently upgraded to the latest Contact Form 7. It was great for word count but didn't restrict the word count. Still searching.

  9. MickeyRoush
    Member
    Posted 1 year ago #

    According to the changelog the latest version supports this now.

    "Support the use of the maxlength attribute for textarea ([textarea] and [textarea*])."

    http://wordpress.org/extend/plugins/contact-form-7/changelog/

  10. jpretorious
    Member
    Posted 1 year ago #

    Thanks I will look into it :)

  11. chaoti
    Member
    Posted 1 year ago #

    @MickeyRoush @jpretorious That's right and I use it, but it only works as a shortener. I described that here: maxlength-function only works as a shortener?

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic