Page 1 of 1
How do I change a value with php?
Posted: Sat Nov 19, 2005 7:36 am
by benArfika
Hello, I have this form on my html page, to send the value to paypal. I would like to change the amount value using php when someone enters a number in a textbox and click a button. If anyone could please explain to me the procedure. I have doen it using javascript, but it was not browser compatible.
Code: Select all
<form name = "price" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="bn" value="webassist.dreamweaver.4_0_3">
<input type="hidden" name="business" value="rockfit@swinggym.com">
<input type="hidden" name="item_name" value="SwingGym">
<input type="hidden" name="item_number" value="0033">
<input type="hidden" name="amount" value="399">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="return" value="http://www.swinggym.com/success.php">
<input type="hidden" name="cancel_return" value="http://www.swinggym.com/cancel.php">
......................
</form>
Posted: Sat Nov 19, 2005 7:48 am
by Chris Corbyn
The only way you can do this with PHP is to submit the form fully to replace the value in the code and then submit the paypal form from there. You could do this by automatic redirect using javascript.
The initial page:
Code: Select all
<form action="page_with_paypal_form.php" method="post">
Enter amount: <input type="text" name="user_amount" />
<input type="submit" name="submit" value="Pay Me!" />
</form>
Then on the page with the paypal form... have JS submit it right away but use some fallback too...
Code: Select all
<?php
$user_value = (!empty($_POST['user_value']) ? $_POST['user_value'] : '');
?>
<form name = "price" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="bn" value="webassist.dreamweaver.4_0_3">
<input type="hidden" name="business" value="rockfit@swinggym.com">
<input type="hidden" name="item_name" value="SwingGym">
<input type="hidden" name="item_number" value="0033">
<input type="hidden" name="amount" value="<?php $user_value; ?>">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="return" value="http://www.swinggym.com/success.php">
<input type="hidden" name="cancel_return" value="http://www.swinggym.com/cancel.php">
<!-- Fallback -->
<noscript>
Please click the "Submit" button to continue: <input type="submit" name="submit" value="Submit" />
</noscript>
......................
</form>
<script type="text/javascript">
<!-- Hide me
document.forms[0].submit(); //Submit the form automatically
// -->
</script>
Posted: Sat Nov 19, 2005 1:42 pm
by illuminationed
I suggest you go to Php.net and look up the $_POST function -
It is very useful
Posted: Sat Nov 19, 2005 3:27 pm
by Chris Corbyn
illuminationed wrote:I suggest you go to Php.net and look up the $_POST function -
It is very useful
$_POST is not a function and I don't think that knowing to use POST variables alone would be particularly useful here since the form needs to go to PayPal.
Posted: Sat Nov 19, 2005 4:30 pm
by John Cartwright
just so you know $user_value was never echo'd in the form.. just sitting there.
Posted: Sat Nov 19, 2005 4:39 pm
by Chris Corbyn
Jcart wrote:just so you know $user_value was never echo'd in the form.. just sitting there.

*Shrugs* Yeah, of course I knew that. I was just testing ya

Re: How do I change a value with php?
Posted: Sat Nov 19, 2005 8:55 pm
by dethron
benArfika wrote:Code: Select all
<form name = "price" action="https://www.paypal.com/cgi-bin/webscr" method="post" target="_blank">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="bn" value="webassist.dreamweaver.4_0_3">
<input type="hidden" name="business" value="rockfit@swinggym.com">
<input type="hidden" name="item_name" value="SwingGym">
<input type="hidden" name="item_number" value="0033">
<input type="hidden" name="amount" value="399">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="return" value="http://www.swinggym.com/success.php">
<input type="hidden" name="cancel_return" value="http://www.swinggym.com/cancel.php">
......................
</form>
Your form has only hidden attributes!!!, what is the way that user changes the amount value? If through another form, put a onClick="myFunction()" to your other form's submit button; where myFunction() is a javascript function.
benArfika wrote:I have doen it using javascript, but it was not browser compatible.
Since PHP is the server-side scripting and Javascript is the client-side scripting, using Javascript is prettier than using PHP. If you must it using PHP then, you have to send the data to the server one more time.
Posted: Sat Nov 19, 2005 11:12 pm
by MilchstrabeStern
I disagree, I think PHP is a perfect option for this. Javascript has a lot of.. maybe I just hate javascript lol.
Posted: Sat Nov 19, 2005 11:46 pm
by dethron
MilchstrabeStern wrote:I disagree, I think PHP is a perfect option for this. Javascript has a lot of.. maybe I just hate javascript lol.
Dont let your prejudices own you. PHP and Javascript are different things. One of them is working on the server-machine and another is working on the clients-machine. There is no need to hate it.
You can hate ASP, and use PHP4 or you can hate ASP.NET and use PHP5. Instead of hating javascript, you should combine it with PHP to get excellent web-applications.
