/    Sign up×
Community /Pin to ProfileBookmark

What is <input type="hidden"/>?

Hi! What is <input type=”hidden”/> ?

What is the purpose of it? It always appear at the end of forms. I have searched the web for answers but none seems to explain it clearly. Can someone please enlighten me?

Thanks.

to post a comment
HTML

16 Comments(s)

Copy linkTweet thisAlerts:
@TJ111Sep 18.2007 — It's usually a way people use to store variables that they don't want the user to see, but that they want included with the form information. An example would be on my "Contact Us" form I use PHP to set the value's of hidden inputs to the user's IP address.
Copy linkTweet thisAlerts:
@ZnupiSep 18.2007 — It's usually a way people use to store variables that they don't want the user to see, but that they want included with the form information. An example would be on my "Contact Us" form I use PHP to set the value's of hidden inputs to the user's IP address.[/QUOTE]
You are right but I don't understand why you would store a user's IP address in a hidden field... I mean, you can always read it from $_SERVER['REMOTE_ADDR'], even if you are handling some form info...
Copy linkTweet thisAlerts:
@TJ111Sep 18.2007 — It just made it easier for processing the form information in my mail script (I'm lazy). I use extract($_POST) to get all the variables for my form information. I guess a better example would be on some forms I use it to store values pulled from a database with ajax relative to whatever a user is doing.
Copy linkTweet thisAlerts:
@CentauriSep 18.2007 — Some mail programs like Formmail require fields sent to them with the form data to indicate things like address to send to, the confirmation page url, subject text etc. The hidden field ensures that this is not visible to the user, but still gets sent with the data.
Copy linkTweet thisAlerts:
@ray326Sep 18.2007 — And "hidden from the user" doesn't mean it's secret or secure, just that it isn't visible on the page. It is readily available to anyone who looks at the page source.
Copy linkTweet thisAlerts:
@ZnupiSep 18.2007 — And also changeable through tools like FireBug. I know, I'm being paranoid ?
Copy linkTweet thisAlerts:
@TJ111Sep 18.2007 — And also changeable through tools like FireBug. I know, I'm being paranoid ?[/QUOTE]

Someone could also gain root access to your server, then go to that particular form and delete it!:eek:
Copy linkTweet thisAlerts:
@LeeUSep 18.2007 — It's also not a bad way to stop some spam.
Copy linkTweet thisAlerts:
@firblazerauthorSep 19.2007 — It's usually a way people use to store variables that they don't want the user to see, but that they want included with the form information. An example would be on my "Contact Us" form I use PHP to set the value's of hidden inputs to the user's IP address.[/QUOTE]

Hi! Thanks for your answer.

How do you store variables?
Copy linkTweet thisAlerts:
@felgallSep 19.2007 — Well they are actually constants rather than variables as far as the HTML is concerned - they only become variables in the script that the form content is passed to.

<input type="hidden" name="variableOne" value="firstValue">

<input type="hidden" name="variableTwo" value="2">

will pass two constant values to the form processor along with the values entered into the form fields. If the form is posted to PHP then these two fields would be accessible in PHP as $_POST['variableOne'] and $_POST['variableTwo'] and would have values of 'firstValue' and 2 respectively. If a different server side scripting language is used then the same two fields would be passed, just the exact wat that the two fields are named would be different.
Copy linkTweet thisAlerts:
@TJ111Sep 19.2007 — Felgall is right in that they aren't variables. They are constant form values, and get passed with the form the same as any other user type input. You can have them set as preset values written into the page, or use some sort of scripting (server-side or client side, ie. PHP/javascript) to define the values.
Copy linkTweet thisAlerts:
@ray326Sep 19.2007 — I'm not sure "constant" is the right term for them. Their values can be changed via scripting on the page and they are used that way quite often.
Copy linkTweet thisAlerts:
@TJ111Sep 19.2007 — lol I'm not one for always using the proper terminology, but I can clarify. They are essentially equivalent to other <inputs> in functionality, except that you control their value, not the user.
Copy linkTweet thisAlerts:
@felgallSep 19.2007 — I'm not sure "constant" is the right term for them. Their values can be changed via scripting on the page and they are used that way quite often.[/QUOTE]

You can change any of the HTML from JavaScript - that doesn't make the entire HTML a variable. The value may be a variable in JavaScript but it is a contant in HTML because HTML does not provide a way to change it.
Copy linkTweet thisAlerts:
@ZnupiSep 20.2007 — It's just a synonym for <input type="text" style="display: none"> only it works with CSS turned off, too. Period.
Copy linkTweet thisAlerts:
@KravvitzSep 20.2007 — It's not quite the same. If I remember correctly, some browsers won't include form controls that have display:none when you submit the form.
×

Success!

Help @firblazer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...