Reputation: 23
Hello everyone i have been trying to add paypal payment system in my website
but when ever i click submit it reset the selected value and choose the first one then submit to paypal.
Here i want it to submit the correct chosen option
. i tied few method but failed.
i hope anyone will help me to solve this problem.
i want it to submit the correct chosen option in Select
. But it submits only first one. please modify the code and comment :)
<form id='paypal-info' method='post' action='#'>
FACEBOOK_ID</br>
<input name="fbid" value="" /></br>
<select class="form-control" value="" name="mode" id="mode">
<option value="gems">1300 Gems $5.00 USD</option>
<option value="gems1">3000 Gems $10.00 USD</option>
<option value="gems2">8000 Gems $25.00 USD</option>
<option value="gems3">17000 Gems $50.00 USD</option>
<option value="gems4">36000 Gems $100.00 USD</option>
<option value="gems5">76000 Gems $200.00 USD</option>
</select>
<input type='submit' name='pay_now' id='pay_now' value='Pay' />
</form>
<?php
if(isset($_POST['pay_now'])){
$data=array(
'merchant_email'=>'[email protected]',
'currency_code'=>'USD',
'thanks_page'=>"http://mywebsite/tools/success.php",
'notify_url'=>"http://mywebsite/tools/cancel.php",
'cancel_url'=>"http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'],
'paypal_mode'=>true,
);
if($_POST['mode'] = gems) {
$product_name = "1300 Gems";
$amount = "5.00";
}elseif($_POST['mode']=gems1){
$product_name = "3000 Gems";
$amount = "10.00";
}elseif($_POST['mode']=gems2){
$product_name = "8000 Gems";
$amount = "25.00";
}elseif($_POST['mode']=gems3){
$product_name = "17000 Gems";
$amount = "50.00";
}elseif($_POST['mode']=gems4){
$product_name = "36000 Gems";
$amount = "100.00";
}elseif($_POST['mode']=gems5){
$product_name = "76000 Gems";
$amount = "200.00";
}
$fbid=$_POST['fbid'];
echo infotutsPaypal($data,$product_name,$amount,$fbid);
}
function infotutsPaypal( $data,$product_name,$amount,$fbid) {
define( 'SSL_URL', 'https://www.paypal.com/cgi-bin/webscr' );
define( 'SSL_SAND_URL', 'https://www.sandbox.paypal.com/cgi-bin/webscr' );
$action = '';
//Is this a test transaction?
$action = ($data['paypal_mode']) ? SSL_SAND_URL : SSL_URL;
$form = '';
$form .= '<form name="frm_payment_method" action="' . $action . '" method="post">';
$form .= '<input type="hidden" name="business" value="' . $data['merchant_email'] . '" />';
// Instant Payment Notification & Return Page Details /
$form .= '<input type="hidden" name="notify_url" value="' . $data['notify_url'] . '" />';
$form .= '<input type="hidden" name="cancel_return" value="' . $data['cancel_url'] . '" />';
$form .= '<input type="hidden" name="return" value="' . $data['thanks_page'] . '" />';
$form .= '<input type="hidden" name="rm" value="2" />';
// Configures Basic Checkout Fields -->
$form .= '<input type="hidden" name="lc" value="" />';
$form .= '<input type="hidden" name="no_shipping" value="1" />';
$form .= '<input type="hidden" name="no_note" value="1" />';
// <input type="hidden" name="custom" value="localhost" />-->
$form .= '<input type="hidden" name="currency_code" value="' . $data['currency_code'] . '" />';
$form .= '<input type="hidden" name="item_name" value="'.$product_name.'" />';
$form .= '<input type="hidden" value="_xclick" name="cmd"/>';
$form .= '<input type="hidden" name="amount" value="'.$amount.'" />';
$form .= '<input type="hidden" name="page_style" value="paypal" />';
$form .= '<input type="hidden" name="charset" value="utf-8" />';
$form .= '<input type="hidden" name="on1" value="'.$fbid.'">';
$form .= '<script>';
$form .= 'setTimeout("document.frm_payment_method.submit()", 1);';
$form .= '</script>';
$form .= '</form>';
return $form;
}
?>
Upvotes: 2
Views: 907
Reputation: 622
i see in the php code you make = in the if statement change it to ==, = used to set value but == used for equality
Upvotes: 2