2013-05-26 37 views
1

我有以下形式如何驗證與PHP的數據貝寶的形式提交前貝寶

<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)的隊名是長至少三個字符的形式之前驗證已提交。我將如何實現這一點?

+0

您或者需要在JS中驗證並從JS提交表單到PayPal,或者您需要將此表單提交給PHP以驗證數據,然後提交給PayPal。 – markdwhite

回答

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>