如何在将其提交到贝宝之前使用 php 数据验证贝宝表单
Posted
技术标签:
【中文标题】如何在将其提交到贝宝之前使用 php 数据验证贝宝表单【英文标题】:How do I validate paypal form with php data before submitting it to paypal 【发布时间】: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" >
<img border="0" src="https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" >
</form>
我想验证(使用 php)在提交表单之前团队名称至少包含三个字符。我将如何实现它?
【问题讨论】:
您要么需要在 JS 中验证并从 JS 提交表单到 PayPal,要么需要将此表单提交给 PHP 来验证数据,然后再提交到 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>
【讨论】:
以上是关于如何在将其提交到贝宝之前使用 php 数据验证贝宝表单的主要内容,如果未能解决你的问题,请参考以下文章