如何使一个PayPal按钮的工作作为一个提交按钮

问题描述:

我有一个形式,一个小问题,如何使一个PayPal按钮的工作作为一个提交按钮

我已经提出,输入用户名和学年和PHP代码后面会邮寄形式雇主的凭证,最初是表格与“提交”按钮相关联,并且工作正常。现在我必须放置一个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 = "[email protected]"; 
 
    $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 fucking 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>

+0

您无法嵌套窗体:http://stackoverflow.com/questions/379610/can-you-nest-html-forms – user4035 2015-02-08 22:59:07

+0

什么是您想要的用户流? – 2015-02-08 22:59:38

+0

首先,你的'$ from'头是无效的。它会垃圾邮件。 'mail()'需要一个有效的'From:'参数是一个电子邮件,而不是一个人的名字。 – 2015-02-08 23:04:36

看一看的PayPal Cart Upload method。您将使用它而不是您现在使用的按钮/表单。

该方法将允许您构建自己的单一表单,并且可以将自己想要的任何参数与variables that PayPal provides(许多为隐藏字段)组合在一起。

您的表单可以提交给一个“处理器”脚本,该脚本根据您自己的表单中的数据执行任何所需的操作,然后还将PayPal数据生成一个URL字符串,用于将用户重定向到PayPal付款。

如果您需要处理数据库的任何事务后处理,电子邮件通知等,您需要使用IPN