I have a registration form with two submit buttons. One submit button is for a free member account, and the other is for a premium member account.
My form code is
<form action="post.php" method="post">
<input type="text" name="name" />
<input type="text" name="mail" />
//submit buttons
<input type="submit" value="signup for free member" />
<input type="submit" value="signup for premium member" />
</form>
if($_POST['name'] and $_POST['mail']){
$user_name = $_POST['name'];
$mail = $_POST['mail']
//How i can know he is preimum or free ?
}
Now how can I tell whether the user clicked on the free button or the premium button?
example:
if($_POST['free_member']){
$member = 'free';
}else{
$member = 'premium';
}
yes, multiple submit buttons can include in the html form. One simple example is given below.
Let's learn the steps of performing multiple actions with multiple buttons in a single HTML form: Create a form with method 'post' and set the value of the action attribute to a default URL where you want to send the form data. Create the input fields inside the as per your concern. Create a button with type submit.
One Form can do a POST submission to one Action method in Controller and hence in order to use multiple Submit buttons inside one single Form, a Switch case has to be implemented inside the Action method.
HTML
<input type="submit" value="signup for free member" name="signup_free"/>
<input type="submit" value="signup for premium member" name="signup_premium"/>
PHP
if($_POST['signup_free'])
{
$member = 'free';
}
elseif($_POST['signup_premium'])
{
$member = 'premium';
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With