Skip to:
Content
Pages
Categories
Search
Top
Bottom

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

  • Avatar of WPwebbouw
    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 3 replies - 1 through 3 (of 3 total)
  • Avatar of solid_snake
    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!

    Avatar of WPwebbouw
    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.

    Avatar of solid_snake
    solid_snake
    Participant

    @solid_snake

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

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

You must be logged in to reply to this topic.