【问题标题】:How do I validate paypal form with php data before submitting it to paypal如何在将其提交到贝宝之前使用 php 数据验证贝宝表单
【发布时间】:2013-05-21 06:54:23
【问题描述】:

我有以下表格

<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" target="_top">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="N8Q3XBTNBV8TY">
<table>
<tr><td><input type="hidden" name="on0" value="Team Name">Team Name</td></tr><tr><td><input type="text" name="os0" maxlength="200"></td></tr>
</table>
<input type="image" src="https://www.sandbox.paypal.com/en_US/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

我想验证(使用 php)在提交表单之前团队名称至少包含三个字符。我将如何实现它?

【问题讨论】:

  • 您要么需要在 JS 中验证并从 JS 提交表单到 PayPal,要么需要将此表单提交给 PHP 来验证数据,然后再提交到 PayPal。

标签: php html paypal


【解决方案1】:

您不能(如果您直接提交到 PayPal,就像您在代码示例中一样),使用 PHP。但是你可以使用javascript。

<script>
// using jQuery, just cuz it's easier for this sort of stuff
$('form[action*="paypal"]').submit(function(event) {
    if ($('input[name="on0"]').val().length < 3) {
        event.preventDefault();
        // alert, or use some other means of displaying an error to the user
        alert('Your Team Name must be at least 3 characters long');
        return false;
    }
});
</script>

【讨论】:

    猜你喜欢
    • 2012-02-15
    • 1970-01-01
    • 2011-07-17
    • 2016-01-17
    • 2013-05-06
    • 2013-12-13
    • 2017-09-25
    • 2011-02-17
    • 1970-01-01
    相关资源
    最近更新 更多