2012-02-18 100 views
1

我期待创建一个捐赠和下载脚本,允许你把自己的金钱数量,然后它会自动下载并带你到贝宝。 0也需要成为期权金额。这里是一个例子:http://www.losttype.com/font/?name=liberator贝宝捐出你喜欢的东西下载

我已经创建了PayPal捐赠脚本并进行了编辑以添加输入金额,但任何人都可以建议一种方法来自动开始下载并允许0作为金额?


也许我应该重新开始,我有以下的代码,允许用户通过PayPal捐赠。这有一个输入金额,并在新窗口中将用户重定向到paypal。 提交以开始下载的最佳方式是什么?即使这个人投入零,而他们可以在另一个窗口捐赠。 代码:

<div class="donate"> 
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank"> 
<input type="hidden" name="cmd" value="_donations"> 
<input type="hidden" name="business" value="myemail"> 
<input type="hidden" name="lc" value="GB"> 
<input type="hidden" name="item_name" value="info"> 
<table> <tr><td>Enter your Amount:</td></tr><tr><td><input type="text" name="amount"  value=""></td></tr> </table> 
<input type="hidden" name="currency_code" value="GBP"> 
<input type="hidden" name="no_note" value="0"> 
<input type="hidden" name="cn" value="Add special instructions to the seller"> 
<input type="hidden" name="no_shipping" value="1"> 
<input type="hidden" name="currency_code" value="GBP"> 
<input type="hidden" name="bn" value="PP-DonationsBF:btn_donate_LG.gif:NonHosted"> 
<input type="image" src="https://www.paypalobjects.com/en_GB/i/btn/btn_donate_LG.gif" border="0" name="submit"> 
<img alt="" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1"> 
</form> 
+0

你的问题是什么? – Repox 2012-02-18 09:36:21

+0

这怎么办?任何人都可以帮我创建脚本来做到这一点? – Hue 2012-02-18 10:08:27

+0

不是没有具体的问题 - 我们在这里帮助您解决您面临的特定问题;不要给你所有你需要的代码。 – Repox 2012-02-18 10:22:21

回答

2

很容易真的。检测是否已选择金额,如果有,则重定向到PayPal。
如果没有,直接重定向到文件。

下面是一个非常基本的,未选中例如:

<?php 

    echo "<p>Donate fixed amount to CharityName</p> 
    <form method='POST' action=''> 
    <select name='currency_code'> 
    <option value='EUR'>EUR</option> 
    <option value='GBP'>GBP</option> 
    <option value='USD'>USD</option> 
    <input type='text' name='donate_amount' value='0'> 
    <input type='submit' name='submit' value='Donate'></form>"; 

    if(!empty($_POST['submit'])) { 
    // Form has been submitted 
     if($_POST['donate_amount'] > 0) { 
    // Redirect to PayPal 
    header('Location: https://www.paypal.com/cgi-bin/webscr?cmd=_donations&item_name=Donation for XXX&amount='.$_POST['donate_amount'].'&currency_code='.$_POST['currency_code'].'&[email protected]&cbt=Download the file&return=http://link-to-the-file&cancel_return=http://back-to-my-website'); 
    } 
    else { 
    // No donation amount entered - proceed to file directly 
    header('Location: http://link-to-the-file/'); 
    } 
} 

    ?> 
+0

嗨罗伯特 - 我想这个版本,并添加我所有的链接等,但不能得到它在任何地方提交表单刷新只是刷新,任何想法为什么? – Hue 2012-02-21 09:43:42

+0

看看你的网络服务器的错误日志;我做了一个快速的本地测试,对我来说工作得很好。 – Robert 2012-02-21 11:56:09

+0

嗯,我看到我在MAMP本地尝试的问题,但没有工作。尝试在线,由于已经发送头文件,它不允许在我的Wordpress主题中。我可以得到这个与WordPress的工作或头是一个问题? – Hue 2012-02-21 12:59:14

0

这似乎更容易从客户端的JavaScript代码来完成。通过点击捐助&下载按钮,JS确定输入的金额。如果它是0,它会打开一个指向下载的新页面并返回false(以停止处理paypal),如果它大于0,它将打开下载页面并返回true(将付款交给paypal)。

+0

如果可能的话,我宁愿用JavaScript来做到这一点。你能否使用suggesti代码?我非常感谢任何帮助 – Hue 2012-02-20 21:44:50