Skip to:
Content
Pages
Categories
Search
Top
Bottom

Profile Field Text Area Max Character or Word Length


  • @mcuk
    Participant

    @mcuk

    Hi all,

    I am looking to limit the number of words or characters (either is fine) that a user is able to type into a profile field text area (set in WP>Users>Profile Fields as a Multi Line Text Area). Reason for this being that I want to include a small bio but don’t want the user going crazy and writing their life story.

    One of the closest solutions I came across was via the link by Dan in here:
    https://buddypress.org/support/topic/validating-xprofile-fields-limit-length/

    Although a good function, the problem with is that it still allows the user to write their life story and only truncates it when calling and displaying the profile field somewhere else (within the item-header div in my case). The original profile text area still shows and allows the full life story to be input without any boundaries.

    I found this which does exactly what i need:
    http://www.mediacollege.com/internet/javascript/form/limit-characters.html

    So my question is can I link a profile field text area created via the WP dashboard with the function from the above link? Or is there another way of getting the desired result?

    Many thanks!

    WP: 4.3.1
    BP: 2.3.3

Viewing 2 replies - 1 through 2 (of 2 total)

  • danbp
    Moderator

    @danbp


    @mcuk
    Participant

    @mcuk

    Hi @danbp thanks for reply.

    Tried the code you wrote in the link above and it works fine. But as with the one referenced in my first post it reduces the string length upon display rather than preventing the user typing in a large number of characters in the first place (and the data being stored in database).

    So moved onto looking at the code snippet by @henrywright for the sign up page. Would be suitable if i could convert it to work with profile fields. Got to this stage with a few q’s:

    function my_textarea_validation() {
        $custom_field_id = bp_get_member_profile_data( 'field=Mini Bio' );	
    	//is the use of $_POST['field_' . $custom_field_id] correct to access desired profile field?
    	if ( strlen( $_POST['field_' .$custom_field_id] ) > 5 ) { 
            global $bp;
            //which $bp->... error message to use?
    	$bp->signup->errors['field_'] = __( 'CUSTOM ERROR MESSAGE', 'buddypress' ); 
        }
    }
    //which hook to use? (to affect the textarea on Profile > Edit navigation tab)
    add_action( '???', 'my_textarea_validation' );
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Profile Field Text Area Max Character or Word Length’ is closed to new replies.
Skip to toolbar