Reputation: 1304
I have two submit button in my webpage. Once a button is clicked (using post method), it will do perform different action.
How do I check which of the two button is clicked by the user?
The code for the two button
<form name="existingForm" method="post" action="">
<div class="alert alert-info" role="alert" style="text-align: center;">
<label>Are you a returning customer?</label>
<input name="button1" type="submit" value="Login Here" />
</div>
</form>
<form name="logingForm" method="post" action="">
<div class="alert alert-info" role="alert" style="text-align: center;">
<label>Are you a returning customer?</label>
<input name="button2" type="submit" value="Login Here" />
</div>
</form>
The code for post method for button 1:
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$buttonPressed = 1;
}
The code for post method for button 2:
if($_SERVER["REQUEST_METHOD"] == "POST")
{
$buttonPressed -= 1;
}
Upvotes: 0
Views: 2429
Reputation: 16782
Why don't you check if the respective button
is pressed or not and then do your stuff? Something like:
<?php
if(isset($_POST['button1']))
{
// your stuff for existingForm
}
else
if(isset($_POST['button2']))
{
// your stuff for logingForm
}
<form name="existingForm" method="post" action="">
<div class="alert alert-info" role="alert" style="text-align: center;">
<label>Are you a returning customer?</label>
<input name="button1" type="submit" value="Login Here" />
</div>
</form>
<form name="logingForm" method="post" action="">
<div class="alert alert-info" role="alert" style="text-align: center;">
<label>Are you a returning customer?</label>
<input name="button2" type="submit" value="Login Here" />
</div>
</form>
Upvotes: 1