Skip to:
Content
Pages
Categories
Search
Top
Bottom

[resolved] How to limit the input of a profile field type multiline text box?


  • WPwebbouw
    Participant

    @wpwebbouw

    I’m using BP custom profile fields to make a directory of professionals. I use a multiline text box for a description field. Now I want to limit the amount of characters one can type in this field. It would be nice if this can be done the same way as Gravity Forms does it. But if that is not possible or too complicated, I will settle for a second best option i.e. limiting the amount of characters that is written to the database with some simple substring / length php processing on the data before it is submitted to the database.

    Can anyone shed some light on posible ways to do this? Are there any BP hooks or functions I can use to accomplish this?

    Another question: is there any filtering on the profile fields to prevent sql injection?

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

  • solid_snake
    Participant

    @solid_snake

    If you have a child theme you can edit memberssingleprofileedit.php and search for

    <textarea rows="5" cols="40" name="” id=”” aria-required=”true”>

    and replace it with:

    <textarea maxlength="250" rows="5" cols="40" name="” id=”” aria-required=”true”>

    Just use change the maxLength value and you are set!


    WPwebbouw
    Participant

    @wpwebbouw

    Thanks @solid_snake for putting me on the right track. As the maxlength attribute is html5 only and doesn’t work in IE and Opera, I went looking for other solutions. I found a javascript solution with a counter that works well after some tweaking:
    http://inmyexperience.com/2003/02/setting-a-maxlength-on-a-texta.html

    Changed the javascript a bit to:

    function textCounter( field, countfield, maxlimit ) {
    if ( field.value.length > maxlimit )
    {
    field.value = field.value.substring( 0, maxlimit );
    alert( ‘You reached the maximum of ‘+maxlimit+’ characters.’ );
    return false;
    }
    else
    {
    countfield.value = maxlimit – field.value.length;
    }
    }

    In the html I changed the keypress event to a keyup event:

    onkeyup="textCounter(this,this.form.counter,1000);"

    Works in all browsers.


    solid_snake
    Participant

    @solid_snake

    @WPwebbouw fantastic! Updated my theme to reflect this update.


    The Doctor
    Participant

    @panicky

    I want to do the same thing with a little bio next to the avatar.

    So where do I start? I’m really new at this, not a developer, but I’ve managed to create a site with modifications after all.

    I want the “bio” field to be limited to 850 characters with a counter. Where do I make the changes and where do I add the function/javascript that is mentioned above?

    Thank you in advance, I’d be very grateful for serious answers, not just hints to the documentation pages.


    boblebad
    Participant

    @boblebad

    Does this still work under 2.0.1 ?

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘[resolved] How to limit the input of a profile field type multiline text box?’ is closed to new replies.
Skip to toolbar