Reputation: 1
I have two similar forms on a site that I'd like to merge into one form with two submit buttons. They use most of the same data.
The first form uses GET to send the data to another server. The second form sends it in an email. I'd like to strongly encourage site users to use option one before trying option two.
I know how to do this with javascript, but not in a way that degrades well. Any other ways to have two submit options? Or other ideas for how to accomplish this? Thanks!
Upvotes: 0
Views: 1559
Reputation: 155
Like everybody said use either checkbox/radio button. And set the one that use GET as the default option
If you don't want to use javascript you can always get the value and of the checkbox/radio and check user choice
Upvotes: 0
Reputation: 7155
Snow Blind provided the good solution, but you can't determine which button was clicked.
Buttons must have different names, not the same.
Example:
<input type="submit" name="server" value="Server" />
<input type="submit" name="email" value="Email" />
<?php
if(isset($_GET['server']))
{
// Send to another server
}
else if(isset($_GET['email']))
{
// Send to email
}
else die("None of buttons was clicked.");
?>
Additionally, if you have a same code in both parts (server and email), you can do the following:
if(isset($_GET['server']) || isset($_GET['email']))
{
// Do something common to both methods
if(isset($_GET['server']))
{
// Send to server
}
else
{
// Send to email
}
}
Better solution, in my opinion, is to put only 1 submit button + a dropdown menu with method to choose.
<select name="sendMethod">
<option value="" disabled>Choose sending method...</option>
<option value="server">Send to another server</option>
<option value="email">Send to e-mail</option>
</select>
Upvotes: 2
Reputation: 1164
You can create two submit buttons and give them the same name
but different value
.
<input type="submit" name="submit" value="Server">
<input type="submit" name="submit" value="Email">
Then you can check $_GET['submit']
or $_POST['submit']
(depending on form method
) to see which submit was used.
Upvotes: -1