Solved

Is there a textarea character limit in PHP

Posted on 2014-03-26
9
386 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 34

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 30

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
 
LVL 30

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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 34

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 108

Accepted Solution

by:
Ray Paseur earned 500 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 108

Expert Comment

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

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Instering to MySQL table 5 19
Problem to page 4 23
CSS measurement 10 14
PHP JSON Clean up 5 0
Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
This article discusses four methods for overlaying images in a container on a web page
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now