Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it bad practice to use hidden fields? [closed]

Tags:

A fellow programmer told me it was 'bad practice' to use hidden fields in my HTML code. Essentially I have a unordered list that a user selects an item based on a category they selected (the categories are pictures). It then calls javascript to set a hidden field to the value the user selected so I can send it along when the form submitted. Is this truly bad practice, is there another way I should be doing this?

like image 582
ios85 Avatar asked Nov 29 '12 21:11

ios85


People also ask

When would you use a hidden 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.

Which is correct about hidden form fields?

Hidden form field is used to store session information of a client. In this method, we create a hidden form which passes the control to the servlet whose path is given in the form action area. Using this, the information of the user is stored and passed to the location where we want to send data.

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.

Why we use hidden fields in asp net?

The HiddenField control is used to store a value that needs to be persisted across posts to the server. It is rendered as an <input type= "hidden"/> element. Normally view state, session state, and cookies are used to maintain the state of a Web Forms page.


2 Answers

hidden fields exist so one can set a value in a form without displaying an input, i fail to understand how it is bad practice to use them. if you need to create a custom widget and send it's value via a form it is the easiest way to do it , you could still use select buttons with dynamic select lists but you'll have to do ugly hacks to make the interface look pretty.

like image 161
mpm Avatar answered Sep 23 '22 16:09

mpm


This is a very common practice. The only issue I can think of in your case is that it'll break if your visitor has JavaScript disabled, so you might want a fallback.

like image 38
Christophe Avatar answered Sep 23 '22 16:09

Christophe