Page 1 of 1
Beginner question about customizing paypal buttons
Posted: Tue Dec 29, 2009 10:34 am
by karleyb
I have a site where I am going to sell both hard copy and downloadable e-copies of a book. How can I use PHP to capture printed vs. e-book and then customize the paypal button within the same form. It seems like I need to create a custom button and then customize the paypal button after the form is processed. NOt sure I am explaining this well. If I create my own button how do I call the paypal code without the buttom. Any help would be appreciated.
Re: Beginner question about customizing paypal buttons
Posted: Tue Dec 29, 2009 9:37 pm
by omniuni
They paypal code is pretty easy. A basic button looks like this:
Code: Select all
<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input src="gfx/addc.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" type="image" style="border: none;" align="right">
<input name="add" value="1" type="hidden">
<input name="cmd" value="_cart" type="hidden">
<input name="business" value="YOUR_EMAIL_ADDRESS" type="hidden">
<input name="item_name" value="YOUR_ITEM_NAME" type="hidden">
<input name="amount" value="ITEM_COST" type="hidden">
</form>
To customize the button, just make have PHP read a form value, and replace YOUR_ITEM_NAME and ITEM_COST with the appropriate values.
Re: Beginner question about customizing paypal buttons
Posted: Wed Dec 30, 2009 7:49 pm
by karleyb
I need to customize the paypal values depending upon which radio button was selected. How do I get the value of a radio button before the user has submitted since the form action points to the paypal function? I have looked everywhere on the Internet for how to do this and only see that you can get the values after the form is posted. This is my paypal form:
<form id="form1" name="form1" action="
https://www.sandbox.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="business" value="3L92AW5YFFSAU">
<input type="hidden" name="lc" value="US">
<? if ($purchase == 'printed'){ ?>
<input type="hidden" name="amount" value="13.95">
<input type="hidden" name="shipping" value="4.50">
<? } else { ?>
<input type="hidden" name="notify_url" value="
http://www.timespaceorg.com/paypal.php">
<input type="hidden" name="amount" value="11.95">
<? } ?>
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="cn" value="Add special instructions to the seller">
<input type="hidden" name="return" value="
http://www.timespaceorg.com/thankyou.html">
<input type="hidden" name="cancel_return" value="
http://www.timespaceorg.com/order_book.php">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">
<input type="image" src="
https://www.sandbox.paypal.com/en_US/i/ ... wCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<img alt="" border="0" src="
https://www.sandbox.paypal.com/en_US/i/scr/pixel.gif" width="1" height="1">
$pPUrchase s
Re: Beginner question about customizing paypal buttons
Posted: Wed Dec 30, 2009 8:33 pm
by omniuni
You know, Paypal will take values that aren't hidden. In other words, you can have one of the paypal values dependent on radios, and not built in to the form. Does that save you some trouble?
Re: Beginner question about customizing paypal buttons
Posted: Wed Dec 30, 2009 8:39 pm
by karleyb
I'm still not sure how to do this. I tried to look at the radio box value with this
<? if ($purchase.value == "printed"){ ?>
but the value doesn't seem to be set??
Re: Beginner question about customizing paypal buttons
Posted: Wed Dec 30, 2009 8:59 pm
by omniuni
What language is that?
Re: Beginner question about customizing paypal buttons
Posted: Wed Dec 30, 2009 9:07 pm
by karleyb
PHP. I am a newbie to it.
Re: Beginner question about customizing paypal buttons
Posted: Thu Dec 31, 2009 7:35 am
by omniuni
Uh, ok.
So, let's start with a few basics.
Open and close PHP with full tags: <?php ?>
Use "
echo" for output.
The dot (.) is your concatenation symbol, so 'this '.'that' would become "this that". You just nest functions if you need to. It's not Javascript. To get information, you call your $_GET or $_POST arrays.
If I have
<input type="text" name="testvalue" /> and I want to get information from it and print it:
Code: Select all
<?php //see the full tag?
if(isset($_GET['testvalue'])){ //testvalue is now an entry in the $_GET array
echo htmlentities(stripslashes($_GET['testvalue']));
//all code lines end with a semicolon, also, see the nested functions?
}
?>