<form name="myForm" action="http://www.PuStudy.Com/resources/html-forms-action.html"> <input type="hidden" name="myHiddenField" value="12345"> <button>Submit Hidden Field</button> </form>
The above example demonstrates usage of the
<input> element with the
type attribute set to
hidden value represents an abitrary string. The field is hidden from the user — no control is displayed.
A hidden control can be used to submit a value to the script that processes the form without the user needing to include it (or even needing to know about it).
<input> element is in the Hidden state (eg, you have specified
type="hidden"), that element represents a value that is not intended to be examined or manipulated by the user.
Hidden form controls were initially created as a work around to the statelessness of HTTP. They allowed authors (and still do) to pass values back to the server when a form is submitted. For example, a hidden field could contain the ID of an article when a user submits a comment against that article.
The HTML 3.2 specification had this to say about hidden form fields:
These fields should not be rendered and provide a means for servers to store state information with a form. This will be passed back to the server when the form is submitted, using the name/value pair defined by the corresponding attributes. This is a work around for the statelessness of HTTP. Another approach is to use HTTP "Cookies".