2 post submit buttons

Two post submit buttons on same page.  If button1 do something. If button2 Do something
LVL 1
rgb192Asked:
Who is Participating?
 
Ray PaseurCommented:
http://www.laprbass.com/RAY_two_submit_buttons.php
<?php // RAY_two_submit_buttons.php
error_reporting(E_ALL);
echo "<pre>";

// TWO BUTTONS ON ONE HTML PAGE - PHP DECIDES WHICH PROCESS BY EXAMINING THE SUBMIT BUTTON

// TEST THE SUMBIT BUTTON AND PROCESS FORM ONE IF SET
if (isset($_POST["submit1"]))
{
    echo "YOU SUBMITTED FORM NUMBER 1" . PHP_EOL;
    die("WORK COMPLETE");
}

// TEST THE SUMBIT BUTTON AND PROCESS FORM TWO IF SET
if (isset($_POST["submit2"]))
{
    echo "YOU SUBMITTED FORM NUMBER 2" . PHP_EOL;
    die("WORK COMPLETE");
}
// END OF PHP PROCESSING - PUT UP THE FORMS
?>
<form method="post">
THIS IS FOR BUTTON NUMBER ONE
<input type="submit" name="submit1" value="PROCESS ONE" />

THIS IS FOR BUTTON NUMBER TWO
<input type="submit" name="submit2" value="PROCESS TWO" />
</form>

Open in new window

0
 
Ray PaseurCommented:
Give the buttons different names and/or different values.  Test for them in $_POST.
0
 
kumaranmcaCommented:
0
 
Ray PaseurCommented:
BTW, you can also have multiple forms on the same page.  The same principles apply.  Test the data in $_POST or $_REQUEST to see what has been submitted.  And accept only known good values!
0
 
rgb192Author Commented:
this is the best answer because it is the exactly what I am looking for.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.