Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 Submit buttons on 1 form problem 2

Status
Not open for further replies.

ZOR

Technical User
Jan 30, 2002
2,963
GB
I am trying to make this work. Despite either submit button being pressed, both continue with the page its posted to, neither makes the page change??

The 1st Form - 2 Submit buttons. The code on the form is:

<input type="submit" value=" Place Order " name="B2" style="font-weight: 700"><input type="submit" value="Return to Menu" name="B1" style="font-weight: 700"></p>

The form it gets posted to has this in the very front:

if (isset($_POST['submit']) && $_POST['submit'] == 'Return to Menu') {
header('location: newmenu.php');
exit(); }

Can anyone see/tell me where it's going wrong. Many thanks
 
throw some debug output in there and see what's happening:
Code:
echo "submit: " . $_POST['submit'];

if (isset($_POST['submit']) && $_POST['submit'] == 'Return to Menu') {
    header('location: newmenu.php');
    exit();
}

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
It's probably because you've named your submit buttons.

Because of that, you won't have an element of $_POST called 'submit'. You should, depending on which button is clicked, have a element named "B1" or "B2".

But test for yourself. Using the following:

[tt]test_doublesubmit.html[/tt]:
Code:
<html><body><form method="post" action="show_post.php">
<input type="submit" value=" Place Order " name="B2" style="font-weight: 700">
<input type="submit" value="Return to Menu" name="B1" style="font-weight: 700">
</form></body></html>

[tt]show_post.php[/tt]:
Code:
<?php
print '<html><body><pre>';

print_r ($_POST);

print '</pre></body></html>';
?>

play around and verify what is submitted.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
sleipnir214,

multiple submit buttons with the same name should be ok, since only the button that is clicked transmits its name/value


-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
Many thanks. The print_r ($_POST); reveals

[S1]=>
[B1]=> Return to Menu

So does that infer there is no Submit?

How does it get [S1]? Button names are B1 and B2?


 
ah - that's your problem right there - you've named them B1 and B2

this
if (isset($_POST['submit']) && $_POST['submit'] == 'Return to Menu') {
header('location: newmenu.php');
exit();
}

should be this
if (isset($_POST['B1']) && $_POST['B1'] == 'Return to Menu') {
header('location: newmenu.php');
exit();
}

but you could simplify to this since you only have one button named B1:
if (isset($_POST['B1'])) {
header('location: newmenu.php');
exit();
}

-jeff
try { succeed(); } catch(E) { tryAgain(); } finally { rtfm(); }
i like your sleeves...they're real big
 
That did it Jeff, thanks very much. Your print_r ($_POST);
produced submit on it's own.

Thank you all very much, I can pack it in for the night now knowing that one's dead and buried. I will remember the debug outputs next time. All have stars on me, thanks again.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top