BuddyDev

Search

[Resolved] Buddypress User Contact Form Character Limit

  • Participant
    Level: Master
    Posts: 171
    JohnnyNW on #31371

    Hi, just got Buddypress User Contact Form – works perfect, except only 1 question: is there a way to set character limits? Like 1,000 characters?

    Thank you!

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #31382

    Hi JJ,
    Thank you for using the plugin.

    It’s a great suggestion. Please allow me 2 working days to think a bit more about extending it(we can do it currently via code, I am going to explore a flexible option).

    I will be writing back on Monday with a solution.

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 171
    JohnnyNW on #31395

    Sounds great. Thank you.

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #31556

    Hi JJ,
    Thank you for the patience.

    Please upgrade to the latest version. Currently, I have left it to be done via code. Adding a UI option will need more thought(min/max and other conditions for each field).

    Please put the following code in bp-custom.php and it will restrict 1000 characters.

    
    add_filter( 'bpucf_form_validation_errors', function ( $errors ) {
    
    	$message = isset( $_POST['message'] ) ? trim( wp_unslash( $_POST['message'] ) ) : '';
    
    	// let us put our conditions here.
    	// is the length is greater than 1000, add error.
    	if ( strlen( $message ) > 1000 ) {
    		$errors->add( 'message', __( 'Message should have 1000 or less characters.' ) );
    	}
    
    	return $errors;
    } );
    
    

    Regards
    Brajesh

  • Participant
    Level: Master
    Posts: 171
    JohnnyNW on #31559

    Thank you for the updated plugin, and bp-custom.php code. I ran a bunch of tests – everything working as designed 🙂

    Thank you!

  • Keymaster
    (BuddyDev Team)
    Posts: 24706
    Brajesh Singh on #31562

    Hi JJ,
    Thank you.

    I sincerely appreciate you testing it. I am glad it worked.

    Regards
    Brajesh

The topic ‘ [Resolved] Buddypress User Contact Form Character Limit’ is closed to new replies.

This topic is: resolved