HTML forms. different buttons, different actions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
boo_lolly
Forum Contributor
Posts: 154
Joined: Tue Nov 14, 2006 5:04 pm

HTML forms. different buttons, different actions

Post by boo_lolly »

hello all, i'm building a CMS and i'm have some trouble with a certain page i've been working on. I have information stored in my database that the admin user can edit and update and change, obviously. on this edit page i have HTML input fields that have been pre-populated with the variable values.

underneath all of that, i have 3 html submit buttons. one of them is "Cancel", another is "Save and Exit", and the last is "Save and Continue".

if the admin presses cancel, i want to keep the values that are already stored in the database, and go to a certain page.

if the admin presses save and exit, i want all the changes that have been made to update the database, and then go to a certain page.

if the admin presses save and continue, i want all the changes that have been made to update the database, and then go to a different page.

got it? how do i do this? i was thinking wrapping it all up in one html form, and replacing action= with action=<?php echo $submit_value ?> or something like that. and on each submit button the name could be the value of $submit_value. maybe with some if() statements. i dunno. help!
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

if javascript is an option, I'd write a new value to a hidden form var and then handle the request on the action page accordingly.
User avatar
boo_lolly
Forum Contributor
Posts: 154
Joined: Tue Nov 14, 2006 5:04 pm

Post by boo_lolly »

nah, unfortunately javascript isn't an option however i DID think of that. what i believe i'm going to end up doing is adding if() and elseif() statements at the top of the forwarding pages to see which one was clicked, and then take a certain action depending on which one was clicked. dirka.
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

make sure you test it in all browsers, some browsers handle button clicking differently.
User avatar
boo_lolly
Forum Contributor
Posts: 154
Joined: Tue Nov 14, 2006 5:04 pm

Post by boo_lolly »

GOOD call burrito! thanks for the tip! happy tokin'!
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

boo_lolly wrote:happy tokin'!
8O
User avatar
boo_lolly
Forum Contributor
Posts: 154
Joined: Tue Nov 14, 2006 5:04 pm

Post by boo_lolly »

Jcart wrote:
boo_lolly wrote:happy tokin'!
8O
maple leaf indica =)
Post Reply