在帖子中包含 Paypal 按钮生成器的结果,无需复制/粘贴

发布于 2024-12-04 19:05:19 字数 3041 浏览 0 评论 0原文

我拥有当地独有的贸易形式,供人们向当地其他人出售物品。我希望可以选择在新帖子中包含 Paypal“立即购买”按钮,但我一直不知道如何在新帖子中包含该按钮,而无需用户手动复制/粘贴 HTML。我制作了一个简单的 Paypal 按钮生成器,带有复选框和 jQuery,用于在选中复选框时显示表单字段。这里是 jsfiddle

HTML

<form>
<input type="checkbox" id="checkme" /> Add a "Buy Now" Paypal button 
</form>
<div id="extra">
<form action="includes/paypal_button.php" method="post">
Paypal account email: <input type="text" name="email" /><br />
Short item description: <input type="text" name="item" /><br />
Price for item (all amounts are in USD): <input type="text" name="amount" /><br />
Tax amout: <input type="text" name="tax" /><br />
Shipping and handling: <input type="text" name="shipping" />
<input type=submit value="Create Paypal button!">
</form>
</div>

jQuery

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        
        //Hide div w/id extra
       $("#extra").css("display","none");
        // Add onclick handler to checkbox w/id checkme
       $("#checkme").click(function(){
        
        // If checked
        if ($("#checkme").is(":checked"))
        {
            //show the hidden div
            $("#extra").show("fast");
        }
        else
        {      
            //otherwise, hide it 
            $("#extra").hide("fast");
        }
      });
    
    });
</script>

控制器表单位于单独的 php 脚本中, paypal_button.php

HTML

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo htmlspecialchars(($_POST["email"]))?>" >  
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="<?php echo htmlspecialchars(($_POST["item"]))?>">
<input type="hidden" name="amount" value="<?php echo htmlspecialchars(($_POST["amount"]))?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="tax_rate" value="<?php echo htmlspecialchars(($_POST["tax"]))?>">
<input type="hidden" name="shipping" value="<?php echo htmlspecialchars(($_POST["shipping"]))?>">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<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" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

所以应该我将控制器(要打印的按钮)包含在 php if 语句中,该语句将在新表单帖子中打印按钮?如果有人能指出我正确的方向,我将不胜感激。

提前致谢

I own a locally exclusive trade form for people to sell items to others locally. I want to have an option to include a Paypal "Buy Now" button in new posts but I'm stuck at how to include the button in a new post without having the user manually copy/past the HTML. I have made a simple Paypal button generator with a checkbox and jQuery to display form fields if checkbox is checked. Here it is on jsfiddle

HTML

<form>
<input type="checkbox" id="checkme" /> Add a "Buy Now" Paypal button 
</form>
<div id="extra">
<form action="includes/paypal_button.php" method="post">
Paypal account email: <input type="text" name="email" /><br />
Short item description: <input type="text" name="item" /><br />
Price for item (all amounts are in USD): <input type="text" name="amount" /><br />
Tax amout: <input type="text" name="tax" /><br />
Shipping and handling: <input type="text" name="shipping" />
<input type=submit value="Create Paypal button!">
</form>
</div>

jQuery

<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.js"></script>
<script type="text/javascript">
    $(document).ready(function(){
        
        //Hide div w/id extra
       $("#extra").css("display","none");
        // Add onclick handler to checkbox w/id checkme
       $("#checkme").click(function(){
        
        // If checked
        if ($("#checkme").is(":checked"))
        {
            //show the hidden div
            $("#extra").show("fast");
        }
        else
        {      
            //otherwise, hide it 
            $("#extra").hide("fast");
        }
      });
    
    });
</script>

The controller form is in a separate php script, paypal_button.php

HTML

<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="<?php echo htmlspecialchars(($_POST["email"]))?>" >  
<input type="hidden" name="lc" value="US">
<input type="hidden" name="item_name" value="<?php echo htmlspecialchars(($_POST["item"]))?>">
<input type="hidden" name="amount" value="<?php echo htmlspecialchars(($_POST["amount"]))?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="services">
<input type="hidden" name="tax_rate" value="<?php echo htmlspecialchars(($_POST["tax"]))?>">
<input type="hidden" name="shipping" value="<?php echo htmlspecialchars(($_POST["shipping"]))?>">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<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" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>

So should I include the controller(the button to print) in a php if statement that will print the button in new form posts? It would be highly appreciative if someone could point me in the right direction.

Thanks in advance

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文