Re: Multiple Submit Buttons?
by "Steve Mount" <steve(at)saltyrain.com>
|
| Date: |
Mon, 10 Mar 2003 16:55:25 -0500 |
| To: |
<hwg-techniques(at)hwg.org>, "Mark D Hiatt" <mhiatt(at)unlnotes.unl.edu> |
| References: |
UNL |
| |
todo: View
Thread,
Original
|
|
Give each submit button a separate name. If the button is not named, it is
not sent to the CGI program that is in the form's action. If it has a name,
the name will be sent with the button's value. In your case, assuming the
button is named "add":
<input type=submit name=add value="Add">
and the data sent to the CGI will be:
add=Add
If the user presses the normal button, labelled "Submit" perhaps, then the
CGI will not be sent anything special (presuming the "Submit" button is not
given a name, which is pretty normal).
In your CGI, then, you can say, in pseudocode:
if (add_widget_exists)
then
validate_the_data__very_important__
add_the_data
regenerate_the_form
else
show_the_requested_data
endif
Other techniques involve setting a hidden tag with JavaScript, but then you
must be sure your audience has JavaScript turned on.
-------------------------------------------------------------
Steve Mount, Software Engineer steve(at)saltyrain.com
Home Site http://www.saltyrain.com
US Constitution Online http://www.usconstitution.net
----- Original Message -----
From: "Mark D Hiatt" <mhiatt(at)unlnotes.unl.edu>
To: <hwg-techniques(at)hwg.org>
Sent: Monday, March 10, 2003 3:42 PM
Subject: Multiple Submit Buttons?
> I think I've outsmarted myself, again.
>
> I have a form. Within this form are various text boxes, and a few
> MySQL-generated drop-down menus.
>
> In the event that someone wants to select a value that's not on the menu
> list (not, in other words, stored in the db table), I wanted to provide a
> means for them to add their entry by clicking on a button that said "Add"
> just to the right of the drop-down.
>
> So you'd have a drop-down list of "Moe", "Larry" and "Schemp". None of
> those Stooges suit you, so you'd click on the Add button, the page would
> refresh and the drop-down would become a text box. You'd type in "Curly"
> there, and "Curly" would then be added to the Stooges table, to appear the
> next time the page refreshed, and you'd continue to the final [Submit]
> button at the bottom of the page.
>
> In reality, I wanted this to happen with hardware manufacturers (Apple,
> Dell, Gateway, IBM....) and chip manufacturers (AMD, Intel, Motorola....)
> and a couple of others. My problem, I thought, was in how to distinguish
> which button was clicked on the first page. In other words, which "Add"
> button was clicked? I figured that by giving each button a name="value" or
> an id="value" that I could then test for the presence of absence of those
> names and id's on the target page, and then perform some variable-swapping
> and redirect-back as needed.
>
> After putting in a few hours on this, it's starting to look like there's
> no way for the catcher-page to know which button submitted the information
> from the pitcher-page. Is that right? Anyone have any gee-whiz ideas on
> how I might accomplish something like this, if it turns out that I'm (now)
> right and this won't actually work?
>
> Mark D Hiatt
> 501 Stadium Drive - 123.1
> University of Nebraska at Lincoln
> "Better Documentation Through Science"
> (402) 472-0067
>
>
HWG hwg-techniques mailing list archives,
maintained by Webmasters @ IWA
This page is part of a preserved archive of archives.hwg.org. The site is no longer active and its content is not maintained. For enquiries about this archive, write to archive(at)iwanet.org.