如何使 PayPal 按钮用作提交按钮
How to make a PayPal button work as a submit button
我的表格有点问题,
我做了一个输入客户姓名和学年的表格,它后面的 PHP 代码会将证书邮寄给雇主,最初表格连接到 'submit' 按钮,它奏效了。现在我必须放置一个 PayPal 按钮而不是提交按钮,因为这将是一种订购优惠券的方式。
并且 PayPal 按钮不会与 PHP 代码连接。这是我的代码:
<?php
if (isset($_REQUEST['submit'])) {
// Initialize error array.
$errors = array();
// Check for a proper First name
if (!empty($_REQUEST['firstname'])) {
$firstname = $_REQUEST['firstname'];
$pattern = "/^[a-zA-Z0-9\_]{2,20}/";// This is a regular expression that checks if the name is valid characters
if (preg_match($pattern,$firstname)){ $firstname = $_REQUEST['firstname'];}
else{ $errors[] = 'Your Name can only contain _, 1-9, A-Z or a-z 2-20 long.';}
} else {$errors[] = 'You forgot to enter your First Name.';}
// Check for a proper Last name
if (!empty($_REQUEST['lastname'])) {
$lastname = $_REQUEST['lastname'];
$pattern = "/^[a-zA-Z0-9\_]{2,20}/";// This is a regular expression that checks if the name is valid characters
if (preg_match($pattern,$lastname)){ $lastname = $_REQUEST['lastname'];}
else{ $errors[] = 'Your Name can only contain _, 1-9, A-Z or a-z 2-20 long.';}
} else {$errors[] = 'You forgot to enter your Last Name.';}
//Check for a valid Email
if (!empty($_REQUEST['Email'])) {
$Email = $_REQUEST['Email'];
$pattern = "/(.*?){1,10}/";
if (preg_match($pattern,$Email)){ $Email = $_REQUEST['Email'];}
else{ $errors[] = 'Your year can only be numbers and letters.';}
} else {$errors[] = 'You forgot to enter your order.';}
}
//End of validation
if (isset($_REQUEST['submit'])) {
if (empty($errors)) {
$from = "Order in from " . $firstname. ""; //Site name
// Change this to your email address you want to form sent to
$to = "scoildaracookthebooks@gmail.com";
$subject = "Amanda! Someone bought a card!" . $firstname . "";
$message = "Message from " . $firstname . " " . $lastname . " has just purchased a card, make sure to check the account before you give them a card!
School year: " . $Email . " ";
mail($to,$subject,$message,$from);
}
}
?>
<?php
//Print Errors
if (isset($_REQUEST['submit'])) {
// Print any error messages.
if (!empty($errors)) {
echo '<hr /><h3>The following occurred:</h3><ul>';
// Print each error.
foreach ($errors as $msg) { echo '<li>'. $msg . '</li>';}
echo '</ul><h3>Your order could not be sent due to input errors.</h3><hr />';}
else{echo '<hr /><h3 align="center">Your order was sent to Amanda. Thank you!</h3><hr /><p>Below is the contact details that you sent out to us.</p>';
echo "<u>Order €20 voucher from " . $firstname . " " . $lastname . " </u><br /><b>School year: </b> ".$Email."";
}
}
//End of errors array
?>
</div>
</div>
</div>
<div class="clearfix visible-lg"></div>
</div>
<div class="container">
<div class="jumbotron">
<h2>Order now!</h2>
<p>Fill out the form below.</p>
<div class ="form-group">
<form role ="form" action="" method="post">
<label>First Name: <br />
<input name="firstname" type="text" class="form-control" placeholder="- Enter First Name -" /><br /></label>
</div>
<div class ="form-group">
<label>Last Name: <br />
<input name="lastname" type="text" class="form-control" placeholder="- Enter Last Name -" /><br /></label>
</div>
<div class ="form-group">
<label>School year: <br />
<input name="Email" type="text" class="form-control" placeholder="- Enter School year -" /><br /></label>
</div>
<div class ="form-group">
<!-- This is where the problem starts, the name="submit" won't connect with the PHP code-->
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="HEVRWPVT75BKE">
<input type="image" src="https://www.paypalobjects.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" name="submit" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</div>
</div>
</form>
看看PayPal Cart Upload method。您将使用它来代替您现在使用的 button/form。
该方法将允许您构建您自己的单一表单,并且您可以组合您自己想要的任何参数加上 variables that PayPal provides(许多作为隐藏字段)。
您的表单可以提交给一个 "processor" 脚本,该脚本可以使用您自己的表单数据执行您需要的任何操作,然后还使用 PayPal 数据生成您重定向的 URL 字符串用户使用 PayPal 付款。
如果您需要处理任何 post 数据库事务处理、电子邮件通知等,您需要使用 IPN。
我的表格有点问题,
我做了一个输入客户姓名和学年的表格,它后面的 PHP 代码会将证书邮寄给雇主,最初表格连接到 'submit' 按钮,它奏效了。现在我必须放置一个 PayPal 按钮而不是提交按钮,因为这将是一种订购优惠券的方式。
并且 PayPal 按钮不会与 PHP 代码连接。这是我的代码:
<?php
if (isset($_REQUEST['submit'])) {
// Initialize error array.
$errors = array();
// Check for a proper First name
if (!empty($_REQUEST['firstname'])) {
$firstname = $_REQUEST['firstname'];
$pattern = "/^[a-zA-Z0-9\_]{2,20}/";// This is a regular expression that checks if the name is valid characters
if (preg_match($pattern,$firstname)){ $firstname = $_REQUEST['firstname'];}
else{ $errors[] = 'Your Name can only contain _, 1-9, A-Z or a-z 2-20 long.';}
} else {$errors[] = 'You forgot to enter your First Name.';}
// Check for a proper Last name
if (!empty($_REQUEST['lastname'])) {
$lastname = $_REQUEST['lastname'];
$pattern = "/^[a-zA-Z0-9\_]{2,20}/";// This is a regular expression that checks if the name is valid characters
if (preg_match($pattern,$lastname)){ $lastname = $_REQUEST['lastname'];}
else{ $errors[] = 'Your Name can only contain _, 1-9, A-Z or a-z 2-20 long.';}
} else {$errors[] = 'You forgot to enter your Last Name.';}
//Check for a valid Email
if (!empty($_REQUEST['Email'])) {
$Email = $_REQUEST['Email'];
$pattern = "/(.*?){1,10}/";
if (preg_match($pattern,$Email)){ $Email = $_REQUEST['Email'];}
else{ $errors[] = 'Your year can only be numbers and letters.';}
} else {$errors[] = 'You forgot to enter your order.';}
}
//End of validation
if (isset($_REQUEST['submit'])) {
if (empty($errors)) {
$from = "Order in from " . $firstname. ""; //Site name
// Change this to your email address you want to form sent to
$to = "scoildaracookthebooks@gmail.com";
$subject = "Amanda! Someone bought a card!" . $firstname . "";
$message = "Message from " . $firstname . " " . $lastname . " has just purchased a card, make sure to check the account before you give them a card!
School year: " . $Email . " ";
mail($to,$subject,$message,$from);
}
}
?>
<?php
//Print Errors
if (isset($_REQUEST['submit'])) {
// Print any error messages.
if (!empty($errors)) {
echo '<hr /><h3>The following occurred:</h3><ul>';
// Print each error.
foreach ($errors as $msg) { echo '<li>'. $msg . '</li>';}
echo '</ul><h3>Your order could not be sent due to input errors.</h3><hr />';}
else{echo '<hr /><h3 align="center">Your order was sent to Amanda. Thank you!</h3><hr /><p>Below is the contact details that you sent out to us.</p>';
echo "<u>Order €20 voucher from " . $firstname . " " . $lastname . " </u><br /><b>School year: </b> ".$Email."";
}
}
//End of errors array
?>
</div>
</div>
</div>
<div class="clearfix visible-lg"></div>
</div>
<div class="container">
<div class="jumbotron">
<h2>Order now!</h2>
<p>Fill out the form below.</p>
<div class ="form-group">
<form role ="form" action="" method="post">
<label>First Name: <br />
<input name="firstname" type="text" class="form-control" placeholder="- Enter First Name -" /><br /></label>
</div>
<div class ="form-group">
<label>Last Name: <br />
<input name="lastname" type="text" class="form-control" placeholder="- Enter Last Name -" /><br /></label>
</div>
<div class ="form-group">
<label>School year: <br />
<input name="Email" type="text" class="form-control" placeholder="- Enter School year -" /><br /></label>
</div>
<div class ="form-group">
<!-- This is where the problem starts, the name="submit" won't connect with the PHP code-->
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="HEVRWPVT75BKE">
<input type="image" src="https://www.paypalobjects.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" name="submit" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
</div>
</div>
</form>
看看PayPal Cart Upload method。您将使用它来代替您现在使用的 button/form。
该方法将允许您构建您自己的单一表单,并且您可以组合您自己想要的任何参数加上 variables that PayPal provides(许多作为隐藏字段)。
您的表单可以提交给一个 "processor" 脚本,该脚本可以使用您自己的表单数据执行您需要的任何操作,然后还使用 PayPal 数据生成您重定向的 URL 字符串用户使用 PayPal 付款。
如果您需要处理任何 post 数据库事务处理、电子邮件通知等,您需要使用 IPN。