Reputation: 1
Would like to get a consensus as to what the best practice is in this scenario:
Muliple submit buttons, is it better to handle this by having separate FORMS for each one of the submits, OR is it okay to have one form and check which button was pressed?
thank you for your input :D
Upvotes: 0
Views: 1084
Reputation: 12440
In my case I would do that similar to Andrew Heath, but I woulg give the buttons a unique name. So the && clause is not needed
Upvotes: 2
Reputation: 6274
Assuming you're doing this solely in PHP, just change the values for each button and check for existence in POST:
if (isset($_POST['button1']) && $_POST['button1'] == "Previous") {
// do something
} else if (isset($_POST['button1']) && $_POST['button1'] == "Next") {
// do something else
} else {
// nothing has been submitted, display default
}
Upvotes: 2
Reputation: 2446
Of course, it always depends on the purpose. However, as a rule-of-thumb, I do the natural thing:
I try to avoid having merged forms (the first option) as:
<form action="blah">
pages.Upvotes: 0
Reputation: 39869
Well, depending on the content of the form, having 2 submit buttons would be the only way to achieve what you want. (How would you have 2 forms if there were text boxes.. replicating the entered data with javascript would be rather annoying)
I would stick with just checking to see which button was pushed, it should be much easier.
Upvotes: 0