Hi,
I using multiple submit buttons with a form and need to determine which
button was used for the form submission back in the controller. This
works fine in Firefox, but I can;t seem to get it to work with Internet
Exploder … ooops… Explorer.
Note: I’m using no Javascript and can’t use and javascript
(accessability reasons) so bog standard xhtml solution needed.
HTML (entire file):
Add Phone Number SaveOffice
Mobile
With Firefox I get the following parameters return to my controller:
Press “Add Phone Number” button:
- Parameters: {“phone_numbers”=>{“1”=>{“external_number”=>“1234”},
“2”=>{“external_number”=>“5678”}}, “_method”=>“put”, “action”=>“update”,
“controller”=>“work”, “person_id”=>“1”, “submitbutton”=>“add_phone”}
Press “Save” button: - Parameters: {“phone_numbers”=>{“1”=>{“external_number”=>“1234”},
“2”=>{“external_number”=>“5678”}}, “_method”=>“put”, “action”=>“update”,
“controller”=>“work”, “person_id”=>“1”, “submitbutton”=>“save_all”}
So because the parameter “submitbutton” shows the value for pressed
button it’s easy to work out what to do.
However in Internet Explorer 6 I get the following result:
Press “Add Phone Number” button:
- Parameters: {“phone_numbers”=>{“1”=>{“external_number”=>“1234”},
“2”=>{“external_number”=>“5678”}}, “_method”=>“put”, “action”=>“update”,
“controller”=>“work”, “person_id”=>“1”, “submitbutton”=>“Add Phone
Number”}
Press “Save” button: - Parameters: {“phone_numbers”=>{“1”=>{“external_number”=>“1234”},
“2”=>{“external_number”=>“5678”}}, “_method”=>“put”, “action”=>“update”,
“controller”=>“work”, “person_id”=>“1”, “submitbutton”=>“Add Phone
Number”}
Oh no … it’s the same value returned each time regardless of the
button. It always returns the text of the first submit button,
regardless of the button actually pressed. If you change the order of
the buttons the new first buttons text will be returned. It doesn’t even
return the value, it returns the text, go figure.
I tried some other combinations:
Add
Phone Number
Save
In firefox:
- Parameters: {“phone_numbers”=>{“1”=>{“external_number”=>“1234”},
“2”=>{“external_number”=>“5678”}}, “_method”=>“put”, “action”=>“update”,
“add_phone_button”=>“add_phone”, “controller”=>“work”, “person_id”=>“1”}
The button that was pressed is included in the parameters, the button
that was not pressed is not included in the parameters.
In Internet Explorer:
- Parameters: {“save_all_button”=>“Save”,
“phone_numbers”=>{“1”=>{“external_number”=>“1234”},
“2”=>{“external_number”=>“5678”}}, “_method”=>“put”, “action”=>“update”,
“add_phone_button”=>“Add Phone Number”, “controller”=>“work”,
“person_id”=>“1”}
Both buttons and there text are included in the parameters, so you can’t
tell which was pressed.
In Internet Explorer 7 it will return the title of button that was
clicked (when both buttons are named the same). When the buttons are
named different it only returns the button that was clicked. (So very
much like FireFox)
So the question is, in Internet Explorer 6, how do I tell which submit
button was pressed when a form has more than one submit button. I
real;ise I could work around this with javascript, but I need this to
work when javascript is disabled.
Cheers,
Anthony R.