Jump to content

Can I auto-submit a form or base two variables on one form element?

- - - - -

  • Please log in to reply
8 replies to this topic

#1
sAuhsoj

sAuhsoj

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
I want to create a paypal button which posts variables. However, I need this to support multiple currencies so I added a dropdown box. The problem is that paypal receives one variable for currency (currency_code) and another for the price (amount). I need to change both of these with the one dropdown menu - how can I do this?

This is what I have so far:
<form action="https://www.paypal.com/cgi-bin/webscr " method="post"> 

<input type="hidden" name="lc" value="en_GB"> 

<input type="hidden" name="cmd" value="_xclick"> 

<input type="hidden" name="business" value="myemail@gmail.com"> 

<input type="hidden" name="item_name" value="MyProduct"> 

<input type="hidden" name="button_subtype" value="services"> 

<input type="hidden" name="no_shipping" value="1"> 

<input type="hidden" name="no_note" value="0"> 

<input type="hidden" name="shipping" value="0.00">

<input type="hidden" name="amount" value="1.99">

<select name="currency_code">

<option value="GBP">GBP</option>

<option value="EUR">EUR</option>

<option value="USD">USD</option>

</select> 

<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">

<input type="image" src="https://www.paypal.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.paypal.com/en_US/i/scr/pixel.gif " width="1" height="1"> 

</form>

Alternatively I could create a page in between where I hold all the variables and change the amount based on what the currency is; whilst auto-submitting these as a form - I discuss this (with myself apparently) down below.

Edited by sAuhsoj, 04 July 2011 - 11:13 AM.


#2
sAuhsoj

sAuhsoj

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
Currently amount is stuck at 1.99

#3
sAuhsoj

sAuhsoj

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
I could create a page in between where I hold all the variables and change the amount based on what the currency is - is there a better way?

#4
sAuhsoj

sAuhsoj

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
Like this:
<html>

	<head>

	<title>PayPal button</title>

	</head>

	<body>

	<form action="https://www.paypal.com/cgi-bin/webscr " method="post"> 

	<input type="hidden" name="lc" value="en_GB"> 

	<input type="hidden" name="cmd" value="_xclick"> 

	<input type="hidden" name="business" value="myemail@example.com"> 

	<input type="hidden" name="item_name" value="My_Product"> 

	<input type="hidden" name="button_subtype" value="services"> 

	<input type="hidden" name="no_shipping" value="1"> 

	<input type="hidden" name="no_note" value="0"> 

	<input type="hidden" name="shipping" value="0.00">

<?php

if ($_POST['currency_code'])

	{

	if ($_POST['currency_code'] == "USD")

		{

		$amount = 1.99;

		}

	else if ($_POST['currency_code'] == "GBP")	

		{

		$amount = 1.39;

		}

	else if ($_POST['currency_code'] == "EUR")

		{

		$amount = 1.49;

		}

	echo

	"

	<input type=\"hidden\" name=\"amount\" value=\"" . $amount . "\">

	<input type=\"hidden\" name=\"currency_code\" value=\"". $_POST['currency_code'] ."\">

	";

	}

?>

	<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynowCC_LG.gif:NonHosted">

	<input type="submit" value="Continue to PayPal">

	</form>

	</body>

	</html>
However, this page seems unnecessary - can I redirect the user automatically?

#5
sAuhsoj

sAuhsoj

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
I also tried naming the form 'autodirect' and adding
<script type="text/javascript"> document.autodirect.submit(); </script>
after the form. however this seems to do nothing at all.

#6
sAuhsoj

sAuhsoj

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
Some people have had the same problem:
auto submit a form? possible? - HTMLCenter Web Development Forums
can PHP submit a form without user clicking button? - Hot Scripts Forums

#7
sAuhsoj

sAuhsoj

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts
Is there any reason why the javascript should not work?

#8
Revolt

Revolt

    Programmer

  • Members
  • PipPipPip
  • 99 posts

sAuhsoj said:

I also tried naming the form 'autodirect' and adding
<script type="text/javascript"> document.autodirect.submit(); </script>
after the form. however this seems to do nothing at all.

As far as I know, javascript doesn't support that kind of "name discovery method". The easiest way to go about this is to give the form an id, for example autodirect.

Then you do.
var form = document.getElementById("autodirect");

form.submit();


#9
sAuhsoj

sAuhsoj

    Learning Programmer

  • Members
  • PipPipPip
  • 41 posts

Revolt said:

As far as I know, javascript doesn't support that kind of "name discovery method". The easiest way to go about this is to give the form an id, for example autodirect.

Then you do.
var form = document.getElementById("autodirect");

form.submit();

Thanks, but this didn't work either - also I think javascript is meant to support this (based on a google search)




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users