【问题标题】:Submit a form according to the choice of the button radio根据按钮单选的选择提交表单
【发布时间】:2020-12-27 17:42:31
【问题描述】:

我正在为学校教育构建一个电子商务 Web 应用程序。 客户可以在三种付款方式之间进行选择。比方说 Paypal、Moneybookers (Skrill) 和 Alertpay。这意味着:每个产品必须有三个“立即购买”按钮。以下是这些按钮的示例:

支付宝

<form action="https://www.paypal.com">
<input type="hidden" name="business" value="payment@mail.com">
<input name="submit" >
</form>

提醒支付

<form action="https://www.alertpay.com">
<input type="hidden" name="business" value="payment@mail.com">
<input name="submit" >
</form>

MONEYBOOKERS

 <form action="https://www.moneybookers.com">
 <input type="hidden" name="business" value="payment@mail.com">
 <input name="submit" >
 </form>

我的目的是在每件产品的前面都有一个“立即购买”按钮。

点击该按钮后,客户将被重定向到一个页面,他们必须通过单选按钮选择一种付款方式。

选择后,他们将通过单击按钮提交选择,然后根据他们的选择登陆 Paypal 或 Alertpay 或 Moneybookers 网站。

我是 PHP 新手,我知道这是可能的,但我不只是知道如何去做。

任何帮助将不胜感激

【问题讨论】:

    标签: php radio-button


    【解决方案1】:

    为每个表单分配一个 ID。例如

    <form id="paypal" action="https://www.paypal.com">
    <input type="hidden" name="business" value="payment@mail.com">
    <input name="submit" >
    </form>
    

    然后将 radios 值设置为 Form Id。例如

    <input type="radio" name="payMethod" value="paypal" class="paymentMethod" /> PayPal<br />
    <input type="radio" name="payMethod" value="aleartPay" class="paymentMethod" /> Alert Pay<br />
    <input type="radio" name="payMethod" value="moneyBookers" class="paymentMethod" /> Money Brookers<br />
    

    然后在按钮单击时执行以下操作

    var selectedMethodId = $(".paymentMethod:checked").val();
    $('#'+selectedMethodId).submit();
    

    【讨论】:

      【解决方案2】:

      如果您想要一个页面,其中选定的单选按钮会更改 action&lt;form&gt;,那么您需要:

      • 在选择单选按钮时将页面提交给服务器。返回的表单具有所需的action 值。

      • 当单选按钮被选中时,使用一些 JavaScript 来设置 action 属性。这样可以避免等待新页面加载。

      但后一种方法确实需要一点代码来处理单选按钮选择事件,你需要考虑是否要支持禁用 JavaScript 的用户。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2012-05-05
        • 2010-09-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多