Submit form then redirect based on button pressed

I have a form with 3 submit buttons.
When the first is pressed the form is submitted then redirected.
When the 2nd is pressed it needs to submit then go to the next record form page (i have this code done)
When the 3rd is pressed it needs to submit then go to the previous record form page (i have this code done).

What I am having trouble with is determining which submit button the user pressed.
How can I set a variable or something so that when they push the save and next button it submits the form and redirects to the proper page and so forth?

The form will submit to $_SERVER['PHP_SELF'] so the code to see which button was used will go in a if(isset($_REQUEST['submit'])) section on the same page as the form resides.

note: I am unable to change the type of form or method of submitting
LVL 3
stealthwifi12Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

amitnepalCommented:
you need to set the buttons name as submit, next and previous. There are two things, name and value for a button type. Value is what is displayed in the button and name is what is used to reference it.

and check with the code :

 if(isset($_REQUEST['submit']))
{
do this
}
else  if(isset($_REQUEST['next']))
{
do this
}
else  if(isset($_REQUEST['previous']))
{
do this
}


hope it helps..
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
scrathcyboyCommented:
You solve this problem by having 3 SEPARATE forms with individual submit buttons for each form.  HTML was never designed to have more than one submit button (technically, one action) per form.  The way to change it is so simple !!  After the first submit button, close the form and start a new one.  After the 2nd submit button, close that form and start the third.  That way each form has its OWN redirect.  This is the way HTML was designed to use forms, and if you follow it, it is hardly any extra coding, and it just works!
0
amitnepalCommented:
Hi,
  Please check the above code provided it should work. It works on that way i have implemented the same. If it doesnot work for any reason, please let me know, i will post the working code.


thanks
Amit
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

stealthwifi12Author Commented:
amitnepal: Since this will be on one form how will I setup the buttons to submit the form and set the value to be caught in your code?

I can not use hidden field's as all of them will be set when the form is submitted


Note - I have solved this another way but am interested if yours can work.
0
stealthwifi12Author Commented:
I got it, your code worked so I'll give you the points. Below is how I used the buttons for future people:
(I dont like using a submit button with the name submit so I used submit1)

<button type="submit" name="submit1" value="submit1">Save Changes</button>
<button type="submit" name="previous" value="previous">Previous</button>
<button type="submit" name="next" value="next">Next</button>


The method I had used was via java script (attached)
<script language="JavaScript">
<!--
function submit_this(idi)
{
document.getElementById("prev2").value=idi
document.forms['zoeken'].submit();
}
-->
</script>


if ($_REQUEST['prev2']=="next")

if ($_REQUEST['prev2']=="prev")

<form name="zoeken" method="post" action="<?php print $_SERVER['PHP_SELF'];?>">

<button type="button" onclick="submit_this('prev');"><-- Previous</button>

<button type="button" onclick="submit_this('next');">Next --></button>

<input type="hidden" id="prev2" name="prev2" value="" />

</form>

Open in new window

0
stealthwifi12Author Commented:
I recommend a more detailed solution in the future, since I am not familiar with HTML adding the 3 example buttons would have been nice.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.