Howdy_McGee Posted June 7, 2011 Share Posted June 7, 2011 So currently I am trying to create a form filled with options. Some of these options include radio buttons and drop down lists in which the user can select different variations of this 1 product. Then it will sum it all up and send 1 solid price to paypal. Well that is what I want it to do anyway. See Paypal gives me a simple API to work with in which it takes only 1 amount. My problem is that it will not accept any variables that are set via $_POST. I am trying to get the checked radio buttons value and add it to the value of "Amount" in this form - see below. <form action="https://www.paypal.com" method="post"> <?php echo "<input type='radio' name='group1' value='4.00'>Home"; echo "<input type='radio' name='group1' checked='false' value='10.00'>Work"; ?> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="test@test.com"> <input type="hidden" name="lc" value="US"> <input type="hidden" name="item_name" value="Registration"> <input type="hidden" name="item_number" value="1011010102"> <?php echo "<input type='hidden' name='amount' value='$test'>" ?> <input type="hidden" name="currency_code" value="USD"> <input type="hidden" name="button_subtype" value="services"> <input type="hidden" name="no_note" value="0"> <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest"> <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 $test = $_POST['group1']; ?> **Note** using the above code will not work exactly. Anyone work with Paypal buttons before? Quote Link to comment https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/ Share on other sites More sharing options...
Slave Posted June 7, 2011 Share Posted June 7, 2011 Yeah, I have...You said that it wont work with $_POST....So why not use $_GET ? Quote Link to comment https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/#findComment-1226241 Share on other sites More sharing options...
gizmola Posted June 7, 2011 Share Posted June 7, 2011 Yeah, I have...You said that it wont work with $_POST....So why not use $_GET ? Did you even glance at his code? Quote Link to comment https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/#findComment-1226258 Share on other sites More sharing options...
gizmola Posted June 7, 2011 Share Posted June 7, 2011 Howdy, Your code makes a form. The target of the form is paypal.com. Even if the target was the same script you would not expect this to work without emitting the same form again, however, as the target is paypal.com it most definately will not work, or I should say, there is no way that $test will ever have any values in it. I'm really not sure what you're trying to do here. Quote Link to comment https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/#findComment-1226264 Share on other sites More sharing options...
Howdy_McGee Posted June 7, 2011 Author Share Posted June 7, 2011 :S i'm fairly new @ PHP so im assuming there isn't really anything I can do here to get this to work? I would have to use something like javascript? Quote Link to comment https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/#findComment-1226288 Share on other sites More sharing options...
gizmola Posted June 7, 2011 Share Posted June 7, 2011 On the contrary, there is probably a way to get "it" to work. You have never stated what "it" is clearly enough for anyone to give you any meaningful advice. Quote Link to comment https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/#findComment-1226365 Share on other sites More sharing options...
Howdy_McGee Posted June 7, 2011 Author Share Posted June 7, 2011 Well all I am trying to do currently is have the user check a radio button. Each radio button has a different value assigned to it. When the user clicks on the radio button and submits the form I want the value of the radio button to be set to the value of the "amount" input box - that is where paypal is getting the final product price. I figured it would be easy to just set it with post but apparently it doesn't quite work like that. Quote Link to comment https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/#findComment-1226498 Share on other sites More sharing options...
JonnoTheDev Posted June 7, 2011 Share Posted June 7, 2011 Well all I am trying to do currently is have the user check a radio button. Each radio button has a different value assigned to it. When the user clicks on the radio button and submits the form I want the value of the radio button to be set to the value of the "amount" input box - that is where paypal is getting the final product price. I figured it would be easy to just set it with post but apparently it doesn't quite work like that. To make this simple, what you need to do have the select options on a form prior to the form that submits to paypal. i.e start.php -> end.php Here's a really basic example using an array of products: start.php <?php $products = array('1 month registration' => '10.99','2 months registration' => '15.99','3 months registration' => '25.99'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Select your amount</title> </head> <body> <p>Please select the product you require:</p> <form method="post" action="end.php"> <?php foreach($products as $name => $price): ?> <input type="radio" name="product" value="<?php echo $price; ?>" /> <?php echo $name; ?> $<?php echo $price; ?><br /> <?php endforeach; ?> <input type="submit" /> </form> </body> </html> end.php <?php $products = array('1 month registration' => '10.99','2 months registration' => '15.99','3 months registration' => '25.99'); if($_POST) { if(!empty($_POST['product'])) { $price = $_POST['product']; } else { /* redirect user back to options if they have not selected a product */ header('Location:/start.php'); exit(); } } else { header('Location:/start.php'); exit(); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Continue</title> </head> <body> <p>You have chosen to buy <?php echo array_search($_POST['product'],$products); ?> @ $<?php echo $price; ?></p> <form action="https://www.paypal.com" method="post"> <input type="hidden" name="cmd" value="_xclick" /> <input type="hidden" name="business" value="test@test.com" /> <input type="hidden" name="lc" value="US" /> <input type="hidden" name="item_name" value="Registration" /> <input type="hidden" name="item_number" value="1011010102" /> <input type="hidden" name="amount" value="<?php echo $price; ?>" /> <input type="hidden" name="currency_code" value="USD" /> <input type="hidden" name="button_subtype" value="services" /> <input type="hidden" name="no_note" value="0" /> <input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHostedGuest" /> <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> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/#findComment-1226510 Share on other sites More sharing options...
Howdy_McGee Posted June 7, 2011 Author Share Posted June 7, 2011 ohh ok thats great. So I need to make this kind of a 2 part process in order for this to work correct? Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/#findComment-1226518 Share on other sites More sharing options...
JonnoTheDev Posted June 7, 2011 Share Posted June 7, 2011 There are other ways however this is by far the simplest Quote Link to comment https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/#findComment-1226519 Share on other sites More sharing options...
Howdy_McGee Posted June 7, 2011 Author Share Posted June 7, 2011 amazing! That gives me a much better understand on the POST array and how it's used. That works perfect i'm going to be playing around with this all week ^.^ thanks again! Quote Link to comment https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/#findComment-1226548 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.