Reputation: 21625
I have the following form
<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>
I want to validate (using php) that the team name is at least three characters long before the form is submitted. How would I implement this?
Upvotes: 1
Views: 1263
Reputation: 13766
You can't (if you're submitting directly to PayPal, as you are in your code example), using PHP. But you can use 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>
Upvotes: 4