2 buttons -> 1 form

Cliff Crawford cjc26 at nospam.cornell.edu
Fri Oct 6 18:03:58 EDT 2000


* Nathan <nhiller at san.rr.com> menulis:
| Is it possible to call the same HTML form with two different submit buttons?
| 
| I have a web page that lists several items that users can select with check
| boxes. At the bottom of the page I have two buttons. The first button sends
| information about the checked items to the user by email. The second button
| displays more details about the checked items. The problem is both buttons
| need to call the same form. I am stuck! Please help.

This isn't exactly a Python question, but I'll answer it anyway :)
The trick is to add a NAME attribute to both submit buttons; for
example:

<INPUT TYPE=SUBMIT NAME="button" VALUE="Send email">
<INPUT TYPE=SUBMIT NAME="button" VALUE="More details">

Then in your CGI script check for what the value of "button" is:

form = cgi.FieldStorage()
if form.has_key("button"):
    if form["button"].value == "Send email":
        send_email()
    else:
        more_details()

Another way to do it would be to give the buttons two different values
for their NAME attributes, and then check to see which one was actually
passed to your CGI script.


-- 
cliff crawford       http://www.people.cornell.edu/pages/cjc26/
                     "Man, the Internet is so cool." -Robert



More information about the Python-list mailing list