Jump to content

HTML forms. different buttons, different actions


boo_lolly

Recommended Posts

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!
Link to comment
Share on other sites

give each button a unique name

then when it submits to the page check for which button was pressed.
[CODE]<?php
if($_POST['cancel']){
    header("Location:page_cancel.php");
}elseif($_POST['save_exit']){
    //update database code
    header("Location:page_exit.php");
}elseif($_POST['save_continue']){
    //update database code
    header("Location:page_continue.php");
}else{
    //this will display if something went wrong.
    header("Location:default.php");
}[/CODE]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.