Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does a hidden input field have to be in a form?

Tags:

html

jquery

I have a page where I need to store a value for processing via Ajax/jQuery. I'm using a hidden input field to store this value like this:

<input type="hidden" name="..." id="..." value="..." />

I can access this value through jQuery even if it is NOT in a form (ie: it's just at the start of my HTML output).

Question: even though it works, is it OK/legal to do from a correctness perspective to have a hidden input value which is not part of a form?

like image 641
user13955 Avatar asked Jul 09 '13 08:07

user13955


People also ask

How do you input a hidden field?

The <input type="hidden"> defines a hidden input field. A hidden field lets web developers include data that cannot be seen or modified by users when a form is submitted. A hidden field often stores what database record that needs to be updated when the form is submitted.

Does a hidden input need a label?

An input with a type="submit" or type="button" does not need a label — the value attribute acts as the accessible label text instead. An input with type="hidden" is also fine without a label.

Are hidden form fields submitted?

Yes, they'll get submitted unless they are removed from the document or have the disabled attribute set on them.

Is input type hidden safe?

Since they are not rendered visible, hidden inputs are sometimes erroneously perceived as safe. But similar to session cookies, hidden form inputs store the software's state information client-side, instead of server-side. This makes it vulnerable.

Which choice is the standard way to include a value in a form without making it visible?

We can use different form tag attributes like text boxes, text area, checkboxes, radio buttons, buttons, dropdown list, etc. to collect data from the users. We need to use the HTML <input type=”hidden”> type for hiding the input field. Using this attribute, the input field will no longer be visible on the page.

How do I hide hidden fields in inspect element?

It is not possible to hide elements from the DOM inspector, that would defeat the purpose of having that tool. Disabling javascript is all it would take to bypass right click protection. What you should do is implement a proper autologin.


1 Answers

You can place the hidden input outside of the form if you are retrieving the value for an ajax post with jquery. However, if your application must degrade (meaning work without javascript) you should have the hidden input in the form so it gets posted to the server on form submit.

like image 57
Kevin Bowersox Avatar answered Oct 13 '22 00:10

Kevin Bowersox