< input type='hidden' value='add a new video' name='action' > < input type='submit' value='add a new video' name='submit' >
I'm working on a Cattle Drive assignment, and part of the given code includes a form with the above buttons. The value of both buttons is the same, but the name is different. I assume that the one named action will be used by an action handler, but I don't understand the need for the hidden button. Wouldn't it be the same if there was one button like so:
< input type='submit' value='add a new video' name='action' >
Could you use the form data submitted by the above button in the same way you could use the data submitted by the pair of buttons above?
The 'hidden' element is not a button. It acts just like a 'text' input except that it is hidden from view. When the form is submitted, a request parameter named action with the value 'add a new video' will be submitted to the server.
Now, as to whether it's redundant or not depends upon how the server component is written. To me, it looks like all the info needed is available from the submit button. [ March 24, 2006: Message edited by: Bear Bibeault ]
Aha! Perhaps then the value submitted by the 'hidden' element would be used to call a method in the servlet I'm supposed to write, and a different value submitted by a 'hidden' element in a different jsp would be used to call a different method. Hmmmm. A clue perhaps. Would getting the value from the 'hidden' element be done through the use of getParameterValues( "action" ), as it would for a text field? [ March 24, 2006: Message edited by: Carol Murphy ]
Yes. Request parameters are simply a map of name/values pairs. From the point of view of a servlet, or any other server-side mechanism), the type of element (text, hidden, password, dropdown, and so on) that generated the parameter isn't even known.