表格与Paypal按钮+电子邮件条目

时间:2013-09-05 19:08:50

标签: php javascript forms email paypal

我是这个网站的新手 - 所以如果我做错了什么我会道歉。

基本上,我目前有一个PHP(和javascript)Paypal表单,它向我的客户提供了9个下拉问题。输入这些数据后,他们就可以点击Paypal按钮,价格自动显示,金额取决于他们的选择。

然而,由于Paypal有描述限制 - 我想知道这个表单是否可以向用户发送Paypal页面,然后向我发送一封包含他们数据条目的电子邮件。

这是一个自定义游戏控制器业务,所以我需要知道他们的所有个性化选择。

数据库似乎太复杂了......因为我会不断更新选择。

我将下拉位排序,并按下Paypal按钮。对于变量和价格,使用.csv文件完全正常。但是,我需要它发送电子邮件给自己。

任何人都可以这样做吗?

如果您需要查看当前代码,请告诉我们。真的可以和有人为我这样做。我们很乐意为您的潜在客户提供详细的评论。

<?php
class Controller {


    public $currency;
    public $shipping;

    public $controllerDir = '';

    public $question_four;
    public $question_five;
    public $question_six;
    public $question_seven;
    public $question_eight;
    public $question_nine;
    public $question_ten;
    public $question_eleven;
    public $question_twelve;

    public $show_question_four   = false;
    public $show_question_five   = false;
    public $show_question_six        = false;
    public $show_question_seven  = false;
    public $show_question_eight  = false;
    public $show_question_nine   = false;
    public $show_question_ten        = false;
    public $show_question_eleven = false;
    public $show_question_twelve = false;

    public function readCSV( $file_name ) {

        if ( file_exists($file_name) ) {
            $this->options = '';
            $file = fopen(  $file_name, 'r' );
            while ($row = fgetcsv($file)) {
                $this->options .= '<option value="' . $row[1] . '">' . $row[0] . '</option>';
            }
        }
        else
            $this->options = '<option value="">- Please answer question above -</option>';

        return $this->options;
    }

    public function ShowControllerForm() {

        ?>
        <div id="ctrl_wrapper">
            <form id="ctrlForm" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_top">
            <table>
                <tr>
                    <th style="text-align: left">
                        <H1>Controller Customization</H1>
                    </th>
                </tr>
                <tr>
                    <td>
                        Would you like to customise a brand new controller or send in your own?
                    <br />
                        <select name="question_one" id="question_one">
                            <option value="">- Please select -</option>
                            <?php echo $this->readCSV( $this->controllerDir . 'csv/question_one.csv' ); ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        How do you want to add colour/design to your controller?
                    <br />
                        <select name="question_two" id="question_two">
                            <option value="" selected="selected">- Please select -</option>
                            <?php echo $this->readCSV( $this->controllerDir . 'csv/question_two.csv' ); ?>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td>
                        What design/colour would you like your controller to have?
                            <br />
                        <select name="question_three" id="question_three">
                            <option value="" selected="selected">- Please select -</option>
                        </select>
                    </td>
                </tr>
                <?php if ($this->show_question_four) : ?>
                <tr>
                    <td>
                        What colour would you like the A, B, X and Y buttons?
                            <br />
                        <select name="question_four" id="question_four">
                            <option value="" selected="selected">- Please select -</option>
                            <?php echo $this->readCSV( $this->controllerDir . 'csv/question_four.csv' ); ?>
                        </select>
                    </td>
                </tr>
                <?php endif; ?>
                <?php if ($this->show_question_five) : ?>
                <tr>
                    <td>
                        What appearance do you wish your guide button to have?
                            <br />
                        <select name="question_five" id="question_five">
                            <option value="" selected="selected">- Please select -</option>
                            <?php echo $this->readCSV( $this->controllerDir . 'csv/question_five.csv' ); ?>
                        </select>
                    </td>
                </tr>
                <?php endif; ?>
                <?php if ($this->show_question_six) : ?>
                <tr>
                    <td>
                        Please select a colour for the four LEDs around the guide button.
                            <br />
                        <select name="question_six" id="question_six">
                            <option value="" selected="selected">- Please select -</option>
                            <?php echo $this->readCSV( $this->controllerDir . 'csv/question_six.csv' ); ?>
                        </select>
                    </td>
                </tr>
                <?php endif; ?>
                <?php if ($this->show_question_seven) : ?>
                <tr>
                    <td>
                        What colour do you wish the thumbsticks to be?
                            <br />
                        <select name="question_seven" id="question_seven">
                            <option value="" selected="selected">- Please select -</option>
                            <?php echo $this->readCSV( $this->controllerDir . 'csv/question_seven.csv' ); ?>
                        </select>
                    </td>
                </tr>
                <?php endif; ?>
                <?php if ($this->show_question_eight) : ?>
                <tr>
                    <td>
                        What colour do you want the D-Pad to be?
                            <br />
                        <select name="question_eight" id="question_eight">
                            <option value="" selected="selected">- Please select -</option>
                            <?php echo $this->readCSV( $this->controllerDir . 'csv/question_eight.csv' ); ?>
                        </select>
                    </td>
                </tr>
                <?php endif; ?>
                <?php if ($this->show_question_nine) : ?>
                <tr>
                    <td>
                        If any, what package of MODs would you like installed?
                            <br />
                        <select name="question_nine" id="question_nine">
                            <option value="" selected="selected">- Please select -</option>
                            <?php echo $this->readCSV( $this->controllerDir . 'csv/question_nine.csv' ); ?>
                        </select>
                    </td>
                </tr>
                <?php endif; ?>
                <tr>
                    <td>Current Controller Price
                        <br />
                        <input type="text" readonly="readonly" id="amount" name="amount" value="0.00"><?php echo $this->currency; ?>
                    </td>
                </tr>
                <tr>
                    <td>
                        Shipping <b>UK Only</b> (Special Next-Day Delivery by 1pm)
                    <br />
                        <input type="text" readonly="readonly" id="shipping" name="shipping" value="<?php echo $this->shipping; ?>"><?php echo $this->currency; ?>
                    </td>
                </tr>
                <tr>
                    <td><b>Total</b> <i>(Current Price + Shipping)</i>
                        <br />
                        <input type="text" readonly="readonly" id="total" name="total" value="0.00"><?php echo $this->currency; ?>
                    </td>
                </tr>
                <tr>
                    <td>
                        <input type="hidden" name="cmd" value="_xclick">
                        <input type="hidden" name="business" value="myemail@somewhere.com">
                        <input type="hidden" name="lc" value="UK">
                        <input type="hidden" id="item_name" name="item_name" value="Controller">
                        <!--<input type="hidden" id="amount" name="amount" value="0.00">-->
                        <input type="hidden" name="currency_code" value="GBP">
                        <input type="hidden" name="button_subtype" value="services">
                        <input type="hidden" name="no_note" value="0">
                        <!--<input type="hidden" id="shipping" name="shipping" value="0.00">-->
                        <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest">
                        <input type="hidden" name="os0" value ="here's a bit of a description">
                        <hr size="1"/>
                        <input type="submit" id="submit" value="Purchase Now !" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!" >
                    </td>
                </tr>
            </table>

            <!--<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">-->
            </form>

            <div id="dialog-message" title="Please select an option" style="display:none">
                <p style="padding-top:10px"></p>
            </div>

            <div id="loader"></div>

            <script>
                function ShowMessage( msg ) {
                    $( "#dialog-message p" ).text(msg);
                    $( "#dialog-message" ).dialog({modal: true, width: 350, buttons: {OK: function() {$( this ).dialog( "close" );}}});
                }   
            </script>
        </div>
        <?php

    }

}

&GT;

1 个答案:

答案 0 :(得分:0)

您可以做的是让您的表单提交到PHP脚本,然后该PHP脚本将您的订单信息保存到数据库,通过电子邮件等发送给您。一旦脚本完成,您可以简单地重定向到PayPal订单金额。一个例子:

<?php
if (isset($_POST['submit'])) {
    // get user's options and calculate price
    // either save to database, send order details via email, or (preferably) both
    // send the user to PayPal to pay for purchase
    $query_data = array(
        'business' => 'your-paypal-email-address',
        'cmd' => '_xclick',
        'item_name' => 'Order #' . $order_id, // $order_id could be last_insert_id() from saving database
        'amount' => '100.00', // the cost of the item
        'shipping' => '10.00' // the cost of shipping the item
    );
    header('Location: https://www.paypal.com/cgi-bin/websrc/?' . http_build_query($query_data));
    exit;
}

您需要充实您计算价格的位,并保存到数据库和/或通过电子邮件发送订单详细信息,但应该足以让您前进。它主要是为了演示如何在PHP脚本中重定向到PayPal。