Jump to content

Recommended Posts

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?

 

Link to comment
https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/#findComment-1226264
Share on other sites

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.

Link to comment
https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/#findComment-1226498
Share on other sites

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>

Link to comment
https://forums.phpfreaks.com/topic/238613-php-paypal-hassle/#findComment-1226510
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.