?
Solved

2 post submit buttons

Posted on 2011-05-07
5
Medium Priority
?
259 Views
Last Modified: 2012-05-11
Two post submit buttons on same page.  If button1 do something. If button2 Do something
0
Comment
Question by:rgb192
  • 3
5 Comments
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35712210
Give the buttons different names and/or different values.  Test for them in $_POST.
0
 
LVL 111

Accepted Solution

by:
Ray Paseur earned 2000 total points
ID: 35712215
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
 
LVL 8

Expert Comment

by:kumaranmca
ID: 35712344
0
 
LVL 111

Expert Comment

by:Ray Paseur
ID: 35712468
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
 

Author Closing Comment

by:rgb192
ID: 35721397
this is the best answer because it is the exactly what I am looking for.
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month16 days, 21 hours left to enroll

864 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question