is there a max size to the length of a hidden input in html?
Asked Answered
E

2

102

in other words:

<input type="hidden" value="Can I put as much as I want in here, or is there a limit?" />

and if so, what is it?

Ellis answered 18/11, 2009 at 0:8 Comment(1)
The best asking method I ever seen.Bard
E
66

It depends on the method you send the form with.

With GET, there is a commonly agreed on limit of about 1-2 kilobytes, depending on browser and server limitations.

With POST, there is no technical limit in the browser, but usually one on the server side - see e.g. Apache's LimitRequestBody, PHP's post_max_size and so on.

Estevan answered 18/11, 2009 at 0:14 Comment(6)
Beware the issues pointed out by @naugtur below for text input fields - at least for those there are technical limits imposed by different browsers.Overwhelming
I just ran some tests on 3 somewhat current browsers (IE9, FF 10 ESR, Chrome 24) and they all submitted hidden input values of 100KB without any problem. So the problems with text inputs don't seem to apply here.Overwhelming
how about textareas ?Febri
@FranciscoCorralesMorales it doesn’t matter what type the input field is - what counts is the end result, the sum of all the data you’re sendingEstevan
I found that Safari truncated the hidden input. Using a textarea solved the problem.Jambeau
I just encountered this issue where I have a hidden input with thousands of array values and it's always truncated. Increasing the max_input_vars value in php.ini solved the issue.Gablet
O
30

Warning! I have experienced problems with <input type="text"> when text is longer than 65535 (max signed int size)

Pasting the text seems to cause some weird overflow of content. Spotted in webkit.

[edit]

The size of GET request is not exactly limited the way Pekka wrote. There is a limit of 2083 bytes for the whole GET query string address?params in Internet Explorer only In other browsers there is practically no limit, with FireFox sending GET queries of over 100KB for example. Obviously the server has to allow those.

It's not covered in documentation, so one has to test it to know the limits for other browsers. IE: http://support.microsoft.com/kb/208427

Oilstone answered 8/6, 2012 at 16:54 Comment(6)
+1 I have created this jsFiddle to test what happens when you set an input value to a very long string: jsfiddle.net/3TVPL/6 I have used a string 65537 chars long. In my testing Crome 24.0.1312 and Safari 5.1.7 for Windows both show input boxes as empty after setting the value to that string. Chrome shows the proper non-empty value if I reduce the string to be 65536 chars long. Other browsers (Firefox 17, IE8, IE9, IE10, Opera 12.12) didn't have any problems even with strings much longer (I went up as far as about 1.2 Mb string)Trophy
@Trophy great work. any thoughts on performance? On my weak machine it was a long wait. I guess that's why webkit doesn't render that.Oilstone
Good point, maybe. I didn't do any performance testing at this time. I have a pretty beefed-up machine at work and didn't notice any delay in any of the browsers.Trophy
It made my FF unusable for like a 5 minutes. Putting this much in a form field is not a good idea anyway :)Oilstone
Mobile browsers and proxies can also truncate hidden fieldsStead
The default maxlength for an HTML-<input type="text" /> control is 524288. ( = 512 x 1024 chars) w3schools.com/tags/att_input_maxlength.aspSevern

© 2022 - 2024 — McMap. All rights reserved.