Link to home
Start Free TrialLog in
Avatar of GEMCC
GEMCC

asked on

Is there a textarea character limit in PHP

Hello,

I have created a form in PHP that includes a textarea.  The form information is being sent via e-mail.  Is there a character limit in textarea?

I am using PHP with Pear on a Linux server.

Please advise.

Have a great day,

Don
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

I'm sure there is a browser-based limit, but it's not going to be an issue for emailed content. You will have problems sending the email long before you run into a problem with running out of room on the textarea.

If it's basic form data, you shouldn't need to really worry about limits. If anything, you may want to add the maxlength attribute to the tag and specify your own limit so that someone doesn't put in 10 megabytes of text that then gets emailed to you and sucks up your bandwidth.
In Php you can only truncate the textarea value after the user has submitted it to the server script. But this is not a great idea, because it lets the user believe to have sent a long text whereas a part of it is deleted on the server side.

It's better to ue javascript to set the limit of chars a user can type within the textarea. Give to your text area an id (for instance, <textarea id='mymesage'>) and then use JQuery:

$('#mymessage').on('keypress', function(){
    var limit = 255;
    if($(this).val().length > limit){
        $(this).val($(this).val().substr(0, limit));
    }
});

Open in new window

No, you would normally use JavaScript to check that the users were not entering more characters than you want them to.
Lol. Unless gr8gonzo knew something I ignore, this is a perfect example of how we can interpret  in two opposite ways the same question if the asker isn't precise and descriptive enough!
@Marco - true, although I would suggest that he use the maxlength attribute over Javascript if he wants to enforce a limit. I would also recommend truncating the data on the server-side, as well (just in case a malicious user posts data directly instead of using the form).
ASKER CERTIFIED SOLUTION
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of GEMCC
GEMCC

ASKER

Never mind.  I found the issue.  The script I was using cut the message off.

Thanks for your responses.

Have a great day,

Don
Avatar of GEMCC

ASKER

Answered my question.
:-)  Thanks for the points and thanks for using EE, ~Ray