Solved

Is there a textarea character limit in PHP

Posted on 2014-03-26
9
390 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 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
Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
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 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 109

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 109

Expert Comment

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

Featured Post

Networking for the Cloud Era

Join Microsoft and Riverbed for a discussion and demonstration of enhancements to SteelConnect:
-One-click orchestration and cloud connectivity in Azure environments
-Tight integration of SD-WAN and WAN optimization capabilities
-Scalability and resiliency equal to a data center

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
What does GoogleTagMgr javascripts below do 5 36
Inserting data into database 10 36
html border input line 7 16
Why is PHP Storm giving me an undefined constant error? 4 20
This article discusses four methods for overlaying images in a container on a web page
Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

828 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