Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple submit buttons

Tags:

php

submit

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';
}
like image 532
Osama Tarek Avatar asked Aug 19 '11 22:08

Osama Tarek


People also ask

Can you have multiple submit buttons?

yes, multiple submit buttons can include in the html form. One simple example is given below.

How do you add multiple submit buttons to a form?

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.

Can you have multiple submit buttons in a form MVC?

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.


1 Answers

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';
}
like image 190
Evan Mulawski Avatar answered Oct 21 '22 10:10

Evan Mulawski