Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Is there a textarea character limit in PHP

Posted on 2014-03-26
9
Medium Priority
?
407 Views
Last Modified: 2014-03-27
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
0
Comment
Question by:GEMCC
  • 2
  • 2
  • 2
  • +2
9 Comments
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39956324
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.
0
 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39956335
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

0
 
LVL 29

Expert Comment

by:Paul Jackson
ID: 39956344
No, you would normally use JavaScript to check that the users were not entering more characters than you want them to.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 31

Expert Comment

by:Marco Gasi
ID: 39956345
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!
0
 
LVL 35

Expert Comment

by:gr8gonzo
ID: 39956363
@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).
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 39956378
Practically speaking, no, there is no textarea limit.  The maximum length of the POST-method request is probably somewhere near 2 billion bytes.  If you type 60 WPM, it will take you about 12 years to exceed the maximum length.
0
 

Author Comment

by:GEMCC
ID: 39956407
Never mind.  I found the issue.  The script I was using cut the message off.

Thanks for your responses.

Have a great day,

Don
0
 

Author Closing Comment

by:GEMCC
ID: 39957796
Answered my question.
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 39958616
:-)  Thanks for the points and thanks for using EE, ~Ray
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Find out what you should include to make the best professional email signature for your organization.
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
In this tutorial viewers will learn how to embed an audio file in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: : The declaration should display (CODE) HTML5 is supported by the most recent versions of all major browsers…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Suggested Courses

824 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question