1

我有以下表格

<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)在提交表单之前团队名称至少是三个字符。我将如何实现这一点?

4

1 回答 1

4

您不能(如果您直接提交到 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>
于 2013-05-26T03:12:13.330 回答