How to put 2 different Submit Buttons in a form (with CI)?
codeigniter, forms, paypal
Solution
Edited: see end of the answer
You should do it as you would normally:
View:
<form method="post" action="mysite.com/submit">
<input type="text" name="name1">
<input type="text" name="name2">
<input type="text" name="name3">
<input type="submit" name="sbm" value="Direct">
<input type="submit" name="sbm" value="PayPal">
</form>
In PHP (controller probably):
if($this->input->post('sbm') == "PayPal") {
// do something with PayPal
} else {
// do something with direct payment
}
Edited: If you would like the caption of the button (visible text) to differ from the value, use `<button>` element instead of the `<input type="submit">`:
<button name="payment_type" value="paypal" type="submit">I want to pay with PayPal</button>
<button name="payment_type" value="direct" type="submit">Or should I go with Direct Payment?</button>
Problem
I have a form where I want the user to choose 2 different way to checkout : Let say that the user enters his informations like his address, name and credit info. Using Paypal Pro, at the end, I want him to be able to choose whether or not he wants to checkout through paypal or through direct payment ... that would lead to a second form. By the way, with CodeIgnieter, when following a form with another one, I got the validation process of the second one that always run, I mean when I come from the first form to the second one, in the second form I will see my error messages appears, for each field even if the user didn't try to submit yet. Is there a way to avoid this bug ? Thanks !