如何把两个不同的提交按钮在一个形式(与CI)? [英] How to put 2 different Submit Buttons in a form (with CI)?
问题描述
我有一个表单,我想让用户选择两种不同的方式结帐:
I have a form where I want the user to choose 2 different way to checkout :
让我们说,用户输入他的地址,姓名和信用信息。
使用PayPal Pro,最后,我希望他能够选择是否要通过paypal或通过直接付款...结算,这将导致第二种形式。
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.
顺便说一句,使用CodeIgnieter,当跟着一个窗体与另一个,我得到第二个验证过程总是运行,我的意思是当我从第一个形式到第二个,在第二种形式,我会看到我的错误消息出现,对于每个字段,即使用户没有尝试提交。有没有办法避免这个错误?
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 ?
谢谢!
推荐答案
编辑:见结尾
它通常是:
查看:
<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>
在PHP(控制器可能)中:
In PHP (controller probably):
if($this->input->post('sbm') == "PayPal") {
// do something with PayPal
} else {
// do something with direct payment
}
希望该按钮的标题(可见文本)与该值不同,请使用< button>
元素而不是< input type = submit>
:
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>
这篇关于如何把两个不同的提交按钮在一个形式(与CI)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!