Posted by Jonathan N. Little on 04/17/06 18:01
nettleby@googlemail.com wrote:
> I'm just learning about forms and the submit process. One thing I'm
> confused about is: if there are two submit buttons on a page, then is
> it necessary to have a name for both buttons, or just for one, in order
> that the server can differentiate between the buttons?
>
> for example:
>
> <form action="http://www.htmlcodetutorial.com/cgi-bin/mycgi.pl">
> Firstname:<input type="text" name="fname">
> <br>
> Surname:<input type="text" name="sname">
> <br>
> <input type = "submit" value="Update"/>
> <input type = "submit" value="Reset" name = "reset"/>
> </form>
In your example your reset button should be:
XHTML
<input type="reset" value="Reset" />
or HTML
<input type="reset" value="Reset">
>
> You would get two different strings being submitted here, for the two
> buttons. Is this a valid way of doing things?
If you have more than one submit button if you five them different names
then your receiving script can "see" which button was activated and
process accordingly
<input type="submit" value="Do One Thing" name="do_this">
<input type="submit" value="Do Something Else" name="do_that">
so if the 1st submit button was click the receiving script would see
this key value pair:
do_this="Do One Thing"
or with the second
do_that="Do Something Else"
HTH
--
Take care,
Jonathan
-------------------
LITTLE WORKS STUDIO
http://www.LittleWorksStudio.com
[Back to original message]
|