How do I change a value with php?

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
benArfika
Forum Newbie
Posts: 1
Joined: Sat Nov 19, 2005 7:30 am

How do I change a value with php?

Post 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>
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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>
illuminationed
Forum Newbie
Posts: 8
Joined: Fri Nov 18, 2005 10:13 am

Post by illuminationed »

I suggest you go to Php.net and look up the $_POST function -

It is very useful
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post 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.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

just so you know $user_value was never echo'd in the form.. just sitting there.
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Jcart wrote:just so you know $user_value was never echo'd in the form.. just sitting there.
:oops: *Shrugs* Yeah, of course I knew that. I was just testing ya :P
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Re: How do I change a value with php?

Post 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.
MilchstrabeStern
Forum Newbie
Posts: 9
Joined: Sat Nov 19, 2005 8:06 pm

Post by MilchstrabeStern »

I disagree, I think PHP is a perfect option for this. Javascript has a lot of.. maybe I just hate javascript lol.
User avatar
dethron
Forum Contributor
Posts: 370
Joined: Sat Apr 27, 2002 11:39 am
Location: Istanbul

Post 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.
8O

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. :!:
Post Reply