Why are hidden fields used?

pavanred picture pavanred · May 21, 2010 · Viewed 28.5k times · Source

I have always seen a lot of hidden fields used in web applications. I have worked with code which is written to use a lot of hidden fields and the data values from the visible fields sent back and forth to them. Though I fail to understand why the hidden fields are used. I can almost always think of ways to resolve the same problem without the use of hidden fields. How do hidden fields help in design?

Can anyone tell me what exactly is the advantage that hidden fields provide? Why are hidden fields used?

Answer

Thilo picture Thilo · May 21, 2010

Hidden fields is just the easiest way, that is why they are used quite a bit.

Alternatives:

  • storing data in a session server-side (with sessionid cookie)
  • storing data in a transaction server-side (with transaction id as the single hidden field)
  • using URL path instead of hidden field query parameters where applicable

Main concerns:

  • the value of the hidden field cannot be trusted to not be tampered with from page to page (as opposed to server-side storage)
  • big data needs to be posted every time, could be a problem, and is not possible for some data (for example uploaded images)

Main advantages:

  • no sticky sessions that spill between pages and multiple browser windows
  • no server-side cleanup necessary (for expired data)
  • accessible to client-side scripts