Rewrite JavaScript with PHP functions

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Rewrite JavaScript with PHP functions

Post by brolly »

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]

I have a web with a shopping cart. This first code is where the client chooses which payment they will use to pay. When choosing "Paypal" this "paypal.inc.php include is called but unfortunately is uses this last line made with JavaScript to submit the paypal details. How can I erase this JS line and write some PHP code instead?


In shopping cart :

Code: Select all

switch ($_REQUEST["pmethod"]){
		case "Paypal" : include ("processor/paypal.inc.php"); break;
		case "BankTransfer" : include ("processor/offline.inc.php"); break;
	}
In paypal.inc.php :

Code: Select all

<form name="paypal" action="https://www.paypal.com/cgibin/webscr" method="post">
<input type="hidden" name="cmd" value="_cart"> 
<input type="hidden" name="upload" value="1"> 
<input type="hidden" name="currency_code" value="<? echo $paypal_currency; ?>"> 
<input type="hidden" name="business" value="<? echo $paypal_email; ?>"> 
<?
// id, description, price, quantity, postage
session_start();
$sessionid = $_SESSION["sessionid"];
$fp = fopen ("./sessions/".$sessionid.".dat", "r+");
$coupon = fgetcsv ($fp, 50);
$x = 1;
while ($data = fgetcsv ($fp, 500)) {
	echo "<input type='hidden' name='item_name_$x' value='".$data[1]."'>\n";
	echo "<input type='hidden' name='amount_$x' value='".$data[2]."'>\n";
	echo "<input type='hidden' name='shipping_$x' value='".$data[4]."'>\n";
	echo "<input type='hidden' name='quantity_$x' value='".$data[3]."'>\n";
	$x++;
}
fclose ($fp);
?>
</form>
<script>document.paypal.submit();</script>

Weirdan | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
bdlang
Forum Contributor
Posts: 395
Joined: Tue May 16, 2006 8:46 pm
Location: Ventura, CA US

Post by bdlang »

How can I erase this JS line and write some PHP code instead?
Um, with a text editor? :D

It would appear as though that last line automagically submits the form. There is no PHP equivalent. The only thing you might do to change that is create a standard INPUT element with a submit button to have the user submit the form manually, e.g.
(untested example)

Code: Select all

<input type="submit" name="submit" value="Pay" onClick="javascript:document.paypal.submit();">
</form>
User avatar
brolly
Forum Newbie
Posts: 18
Joined: Thu May 25, 2006 7:24 am
Location: Nevada, U.S.A.

Post by brolly »

How about using curl?
Post Reply