Jump to content

One form with two actions


Paul_Withers

Recommended Posts

Hi, I have a page with a PayPal button at the bottom. I am attempting to run two actions when the PayPal button is pressed. One is to process the PayPal payment and the other that opens another page which I have called testpage.php

 

I have used a script I found online as I have no experience in Javascript, this is meant to run two actions when the PayPal button is clicked. However only the testpage.php opens.

 

Here is what i got, have I done it wrong? Or is there a better way to do this?

<?php
include 'init.php';
include 'includes/overall/header.php';
include 'includes/logo.php';
?>
<script language="Javascript">
<!--
function OnButton1()
{
    document._xclick.action = "https://www.paypal.com/cgi-bin/webscr"
    // document._xclick.target = "_blank";    // Open in a new window

    document._xclick.submit();             // Submit the page

    return true;
}

function OnButton2()
{
    document._xclick.action = "testpage.php"
    document._xclick.target = "_blank";    // Open in a new window

   // document._xclick.submit();             // Submit the page

    return true;
}
-->
</script>

<?php
if (!isset($_SESSION['loggedin'])) {
   die("You must be logged in to view this page!"); //this causes to script to stop executing and lets the user know there is a problem

/*
Note:  instead of the die() function, you could use the echo() function and provide an HTML link back to the login page, or use the header() function to just redirect users to the login page without any message. It is up to you to decide what your application should behave.
*/
}

//else {  //logged in 
elseif (isset($_SESSION['loggedin']) ){  //logged in 

$username = $_SESSION['loggedinuser'];

$results = $con->query("SELECT * FROM user WHERE username = '$username';");
while($row = $results->fetch_array()) {
$business = $row['paypal_email'];


$user_id = $_GET['user_id'];

$results1 = $con->query("SELECT * FROM live_sales WHERE user_id = '$user_id';");
while($row = $results1->fetch_array()) {

$username  			= $row['username'];
$fishtype    		= $row['fishtype'];
$speciesCommon 		= $row['speciesCommon'];
$speciesScientific  = $row['speciesScientific'];
$listing_title    	= $row['listing_title'];
$age 		        = $row['age'];
$quantity	        = $row['quantity'];
$origin       	    = $row['origin'];
$size               = $row['size'];
$environment 		= $row['environment'];
$waterChemistry	    = $row['waterChemistry'];
$temperature       	= $row['temperature'];
$feeding            = $row['feeding'];
$sexing 		    = $row['sexing'];
$compatability	    = $row['compatability'];
$temperament      	= $row['temperament'];
$breeding           = $row['breeding'];
$comments 		    = $row['comments'];
$postage_type	    = $row['postage_type'];
$postage_cost      	= $row['postage_cost'];
$multipostage		= $row['multipostage'];
$cost      			= $row['cost'];


echo "<div class='result'>";
echo "<h3>$speciesCommon</h3>";
echo "<h2>$listing_title</h2>";
echo "<ul class='results'>";
echo "<li>Species</li>" . str_replace("_"," "," $fishtype") . "<br>";
echo "<li>Common Name:</li> $speciesCommon<br>";
echo "<li>Scientific Name:</li> $speciesScientific<br>";
echo "<li>Age:</li> $age<br>";
echo "<li>Quantity:</li> $quantity<br>";
echo "<li>Price per item:</li> £$cost<br>";
echo "<li>Origin:</li> $origin<br>";
echo "<li>Size:</li>$size<br>";
echo "<li>Environment:</li> $environment<br>";
echo "<li>Water Chemistry</li> $waterChemistry<br>";
echo "<li>Temperature:</li> $temperature<br>";
echo "<li>Feeding:</li> $feeding<br>";
echo "<li>Sexing:</li> $sexing<br>";
echo "<li>Compatability:</li> $compatability<br>";
echo "<li>Temperament:</li> $temperament<br>";
echo "<li>Breeding:</li>$breeding<br>";
echo "<li>Comments:</li> $comments<br>";
echo "<li>Postage Type:</li>$postage_type<br>";
echo "<li>Postage Cost:</li> £$postage_cost $multipostage<br>";
?>
</ul>
</div>
<div align='center'>
<form name="_xclick" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<?php echo '<select name="quantity">';
echo "<option value='$quantity'>Maximum of $quantity available</option>";
for ($q=1; $q<=$quantity; $q++) 
{
    echo "<option value='$q'>$q</option>";
}
echo '</select>';

if( $multipostage == "per item" )
    {
    $postage_cost = $quantity * $postage_cost;
    }
    elseif( $multipostage == "Combined Postage" )
    {
	$postage_cost;
    }

?>

<br><br>
<input type="hidden" name="shipping" value="<?php echo $postage_cost ?>">
<input type="hidden" name="business" value="<?php echo $business ?>">
<input type="hidden" name="currency_code" value="GBP">
<input type="hidden" name="item_name" value="<?php echo $speciesCommon ?>">
<input type="hidden" name="amount" value="<?php echo $cost ?>">
<input type="image" src="https://www.paypalobjects.com/en_US/GB/i/btn/btn_buynowCC_LG.gif" border="0" name="submit" onclick="OnButton1(); OnButton2();" alt="PayPal – The safer, easier way to pay online." >
<img alt="" align="center" border="0" src="https://www.paypalobjects.com/en_GB/i/scr/pixel.gif" width="1" height="1"></form>
</div>

<?php
exit();
}
} 
echo 'Sorry but we could not find any results.';
}
include 'includes/overall/footer.php';
?>

Any help is always appreciated

 

aquaman

Link to comment
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.