How to send hidden data
Asked Answered
P

1

33

I have a form(like the one below for example) where I type data, but I also want to send data which are not directly entered by the user, for example a generic Id(for a user in this case)

<form name="input" action="" method="post">
Username: <input type="text" name="user">
<input type="submit" value="Submit">
</form>

Don't know if I have been clear enough, I hope so.

Peper answered 6/7, 2013 at 18:10 Comment(2)
Use input hidden: w3schools.com/jsref/dom_obj_hidden.aspPimpernel
also before answering a questionHance
H
59

try a hidden input:

<input type="hidden" value="foo" name="user_id" />

The user can't see it, but remember that such inputs can be spoofed and need to be validated on the server just like any other input.

Haswell answered 6/7, 2013 at 18:13 Comment(1)
Be careful because the form does not send the hidden input or any input unless the tag contains the name fieldUnderset

© 2022 - 2024 — McMap. All rights reserved.