简体   繁体   English

提交表单中的PayPal捐赠按钮表单

[英]PayPal donation button form inside on submit form

I have a need to submit form with specific values by clicking submit button. 我需要通过单击提交按钮来提交具有特定值的表单。 When clicking submit button I want to be redirected to PayPal where asked for donation. 单击提交按钮时,我想重定向到PayPal,要求捐款。 After submitting donation I need to redirect customer back to my website where form with values are submitted and shown to customer. 提交捐款后,我需要将客户重定向回我的网站,在该网站上提交带有值的表格并显示给客户。 But right now I`m stuck. 但是现在我被困住了。 If I press submit button after paying or canceling donation nothing happens with entered values in my primary form with title and website. 如果我在付款或取消捐赠后按“提交”按钮,则在带有标题和网站的主表格中输入的值都不会发生任何变化。 My Code looks like this: 我的代码如下所示:


    <form action="adding.php" method="post" enctype='multipart/form-data'>
        <table>
        <tr>
            <td class="abc">
                <p id="insert">Title:*</p><br>
                <input type="text" name="title" class="abcd"  value="<?php echo $title; ?>" />
            </td>
            <td class="abc">
                <p id="insert">Website:*</p><br>
                <input type="text" name="website" class="abcd" value="<?php echo $website; ?>" />
            </td>
        </tr>
        </table>
        <input type="submit" value="Submit" id="submit" name="submit" />
    </form>

    <form action="https://www.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="EJJ5RT9MEEJSC">
        <input type="image" src="http://localhost/www/images/submit.png" id="submit" name="submit" border="0" alt="PayPal - The safer, easier way to pay online!">
        <img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
    </form>

    <?php
        $sql2 = "INSERT INTO `www` (title, website)
        VALUES ('$title', '$website')";
    ?>
    <?php 
        if (isset($_POST['submit'])) {

            $con = mysql_connect("localhost","root","");
            if (!$con){
            exit("Can not connect: " . mysql_error());
        }
        mysql_select_db("www",$con);            
    ?>
    <?php           
    if ((strlen($title) < 3) or (strlen($title) > 15)) {
        echo "<h1 id='top'>Title must be between 3 and 15 characters long!</h1>";
    } else if (filter_var($website, FILTER_VALIDATE_URL) === false) {
        echo("<h1 id='top'>Website: Please enter a valid website to your wish.</h1>");
    }
    else
    {   
        mysql_query($sql2,$con);
        mysql_close($con);

        header("Location:index.php");           
    }
    ?>

first add the database related code in adding.php, where the first form submits the values, and in this form (adding.php), use javascript to submit the paypal donation form 首先在adding.php中添加与数据库相关的代码,第一个表单提交值,在此表单(adding.php)中,使用javascript提交贝宝捐赠表单

ie call a javascript function on page unload: call_paypal. 即在页面卸载时调用javascript函数:call_paypal。

function call_paypal() { document.getElementById("paypal_frm").submit();} 函数call_paypal(){document.getElementById(“ paypal_frm”)。submit();}

< form action="https://www.paypal.com/cgi-bin/webscr" id="paypal_frm" method="post" target="_top" > <form action =“ https://www.paypal.com/cgi-bin/webscr” id =“ paypal_frm” method =“ post” target =“ _ top”>

< /form > </表格>

It's done... 完成...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM