Skip to:
Content
Pages
Categories
Search
Top
Bottom

Minimum Topic & Reply Length

  • @katiekat

    Participant

    I know this has been asked before and have searched endlessly through the support threads but I cannot get any of the code supplied to work.

    Is there any way to have a minimum topic and minimum reply length. I want to stop users posting short comments especially on replies and restrict them to a minimum of 50 characters.

Viewing 2 replies - 1 through 2 (of 2 total)
  • @chadschulz

    Participant

    I know this is an old post. However, I’ve been screwing around with various javascript suggestions from other forums and came up with a solution that works (no problems yet discovered). I’m not exactly a code ninja, so if anyone can help to streamline the code let me know.

    Just insert the following lines into a custom javascript for your theme (if you need guidance on this there’s a lot of help available all over wordpress.org and other forums).

    jQuery(function($) {
    	var forum_input = $( '#bbpress-forums textarea' );
    	var forum_button = $( '#bbpress-forums .submit' );
    	var forum_limit = 50;
    	var forum_class = $( '<div class="forum_limit_info"><span>' + forum_limit + 
    	    '</span> characters needed</div>' ).insertAfter( forum_input );
    	forum_button.hide();
    	forum_class.show();
    	
    	forum_input.bind( 'keyup', function() {
    		var forum_length = $(this).val().length;
    		var chars_left = forum_limit - forum_length;
    
    		$( '.forum_limit_info span' ).html( chars_left );
    
    		if (forum_input)
    			( chars_left > 0 ) ? forum_class.show() : forum_class.hide();
    		
    		if (forum_button)
    			( chars_left > 0 ) ? forum_button.hide() : forum_button.show();
    	});
    });

    Basically this function hides the submit button and displays a countdown text counter until the minimum length is reached and then the button appears and the counter disappears.

    There are ways of hard-coding a minimum into php but I believe you have to edit core files and then insert these modified php files into a child theme. I couldn’t figured out how to insert a simple php function that would do what I wanted in a clean and simple way. So javascript it is.

    The forum_limit setting can be anything you want it to be, just change it. And you can customize your topics and replies minimums separately, if needed, with separate javascript functions using textarea#bbp_reply_content, textarea#bbp_topic_content instead of #bbpress-forums textarea.

    For my CSS stylings I chose to put a :before message on the left and the character count on the right using these:

    .forum_limit_info {
      text-align: right;
      font-size: 13px;
      color: red;
      line-height: 1.2;
      margin: 5px 5px 0px;
    }
    
    .forum_limit_info:before {
      float: left;
      content: '(Minimum Length: 50)';
      color: blue;
    }

    CSS Styling is theme dependent and can basically be however you want/need it to be–very flexible.

    I also created a similar javascript function for my site’s commenting system. Here’s that code as well:

    jQuery(function($) {
    	var comment_input = $( '#commentform textarea' );
    	var comment_button = $( '#entry-comment-submit' );
    	var comment_limit = 25;
    	var comment_class = $( '<div class="comment_limit_info"><span>' + comment_limit + 
    	    '</span> characters needed</div>' ).insertAfter( comment_input );
    	comment_button.hide();
    	comment_class.show();
    	
    	comment_input.bind( 'keyup', function() {
    		var comment_length = $(this).val().length;
    		var chars_left = comment_limit - comment_length;
    
    		$( '.comment_limit_info span' ).html( chars_left );
    
    		if (comment_input)
    			( chars_left > 0 ) ? comment_class.show() : comment_class.hide();
    		
    		if (comment_button)
    			( chars_left > 0 ) ? comment_button.hide() : comment_button.show();
    	});
    });

    Good luck to all,

    Chad

    @robkk

    Moderator

    @chadschulz

    thanks for sharing Chad

Viewing 2 replies - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.
Skip to toolbar