0

因为我是初学者,所以我陷入了困境。注意:thankyou.php 中存在电子邮件发送代码

我的问题是我必须存储所选日期并在通过贝宝付款完成后传递到另一个页面。我已经尝试过 php 会话,但没有在我落后的地方。

成功完成交易后,我从贝宝(如 txn_id、payer_email 等)获得了 $_POST 中的所有详细信息,但我没有得到我在表格中选择的日期。

请帮助我走向正确的方向。

我正在研究贝宝集成,我有 1 个表单,其中存在两个字段(index.php)

  1. 选择日期
  2. 票数

代码 index.php :

    <?php

@session_start(); 
    $var_value = $_POST['eventdate'];
    $_SESSION['eventdate'] = $var_value;
    echo $_SESSION['eventdate'];
?>

<form name="_xclick" action="https://www.sandbox.paypal.com/r" method="post">
                      <table border="0" cellspacing="0" cellpadding="5" id="tbl_paypal_form">
                        <tr>
                          <td colspan="2"><div id="ticket_amount">£10 per person</div></td>
                        </tr>
                        <tr>
                          <td>Select Event Date <span class="mandatory">*</span></td>
                          <td><select name="eventdate" id="eventdate" class="form_field">
                              <option value="">Select Date</option>
                              <option value="Sat 14 July 2012">Sat 14 July 2012</option>
                              <option value="Sun 15 July 2012">Sun 15 July 2012</option>
                              <option value="Mon 16 July 2012">Mon 16 July 2012</option>
                            </select></td>
                        </tr>
                        <tr>
                          <td>No. of Tickets <span class="mandatory">*</span></td>
                          <td><input type="text" name="quantity" id="quantity" class="form_field">
                          <span style="color:#bbb; font-size:11px; padding-top:5px;">For ex: 4</span>
                          </td>
                        </tr>
                        <tr>
                          <td colspan="2"><?php
                                if(!empty($errorMessage)) 
                                {
                                    echo("<div id='validation_error'>");
                                    echo("<p class='error_message'>There was an error with your form:</p>\n");
                                    echo("<ul class='error_message'>" . $errorMessage . "</ul>\n");
                                    echo("</div>");
                                }
                            ?></td>
                        </tr>
                        <tr>
                          <td><img src="images/paypal.gif" /></td>
                          <td><input type="image" src="images/btn_paypal.gif" border="0" name="formsubmit" value="Submit" onclick="return ValidateForm();" alt="Make payments with PayPal - it's fast, free and secure!">                              
                          </td>
                        </tr>
                      </table>
                      <input type="hidden" name="cmd" value="_xclick">
                      <input type="hidden" name="business" value="gala@iskconcoventry.com">
                      <input type="hidden" name="currency_code" value="EUR">
                      <input type="hidden" name="item_name" value="Gala Charity Show Tickets">
                      <input type="hidden" name="amount" value="10">
                      <input type="hidden" name="return" value="http://www.vyx.com/gala/thankyou.php">
                      <input type="hidden" name="notify_url" value="http://www.xyx.com/gala/thankyou.php">
                      <input type="hidden" name="cbt" value="Return to The Store">
                      <!--<input type="hidden" name="eventdate" value="<?php echo $_POST['eventdate'];?>">-->
                    </form>

代码:thankyou.php

<?php

session_start();
$ticketdate = $_SESSION['eventdate'];
//echo $_SESSION['eventdate'];
echo $ticketdate;
?>

<pre style="background:#fff;">
<?php print_r($_POST);?>
</pre>

<?php


if($_POST['txn_id'] != "") 
{
    $mail_subject='Ticket Booked for Gala Charity event';
    $mail_body.= 'Hello Dear, <br><br>';
    $mail_body.= 'Below are the ticket booking details for Gala Charity event. <br><br>';
    $mail_body.= '<b>Booking Date : </b>'. $ticketdate .'<br><br>';
    //$mail_body.= '<b>Booking Date : </b>'.trim($_POST['eventdate']).'<br><br>';
    $mail_body.= '<b>Number of tickets buyed : </b>'.trim($_POST['quantity']).'<br><br>';

    $mail_body.= '<b>Transaction ID : </b>'.trim($_POST['txn_id']).'<br><br>';
    $mail_body.= '<b>First Name : </b>'.trim($_POST['first_name']).'<br><br>';
    $mail_body.= '<b>Last Name : </b>'.trim($_POST['last_name']).'<br><br>';
    $mail_body.= '<b>Payers Email  : </b>'.trim($_POST['payer_email']).'<br><br>';
    $mail_body.= '<b>Payment Date : </b>'.trim($_POST['payment_date']).'<br><br>';

    $mail_body.= '<b>Address Name : </b>'.trim($_POST['address_name']).'<br><br>';
    $mail_body.= '<b>Street : </b>'.trim($_POST['address_street']).'<br><br>';
    $mail_body.= '<b>Zip : </b>'.trim($_POST['address_zip']).'<br><br>';
    $mail_body.= '<b>State : </b>'.trim($_POST['address_state']).'<br><br>';
    $mail_body.= '<b>Country Code : </b>'.trim($_POST['address_country_code']).'<br><br>';


    $mail_body.= '<b>Item Name : </b>'.trim($_POST['item_name']).'<br><br>';
    $mail_body.= '<b>Total Amount Paid : </b>'.trim($_POST['mc_currency']).'&nbsp;'.trim($_POST['mc_gross']).'<br><br>';

    $mail_from=$_POST['payer_email'];
    $mail_to = "myname@example.com";

    //$mail_reply_to = $mail_from;
    $mail_headers = "Content-Type: text/html; charset=iso-8859-1\r\nFrom: $mail_from\r\nReply-to: $mail_reply_to\r\n";
    @mail($mail_to, $mail_subject, $mail_body, $mail_headers);

}
?>
4

2 回答 2

2

您应该使用 paypal 的自定义数据字段来发送和接收额外的付款值。只需在表单中添加另一个输入

<input name="custom" type="hidden" value="" />

如果您需要发送两个或多个值,您可以使用分隔符将它们连接起来,|然后在您从贝宝取回它们时处理它们。

编辑

将您的表格更改为

<form name="_xclick" action="https://www.sandbox.paypal.com/r" method="post" onsubmit="buildCustomVar()">

</body>在结束标记之前添加一点 javascript 到您的页面

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
    function buildCustomVar()
    {
        var custom = $('select[name="eventdate"]').val() + "|" + $('input[name="quantity"]').val();
        $('input[name="custom"]').val(custom);
    }
</script>

在服务器端只是简单地爆炸你得到的价值

$temp = explode("|", $_POST['custom']);
$date = $temp[0];
$quantity = $temp[1];
于 2012-06-25T07:55:40.043 回答
1

将您的表格更改为

<form name="_xclick" action="https://www.sandbox.paypal.com/r" method="post" onsubmit="buildCustomVar()">

添加 javascript

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript">
enter code here
    function buildCustomVar()
    {
        var custom = $('select[name="eventdate"]').val() + "|" + $('input[name="quantity"]').val();
        $('input[name="custom"]').val(custom);
    }
</script>
于 2012-11-23T04:43:31.707 回答