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?
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.
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.
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.
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.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With