views:

86

answers:

2

Basically Iv got PayPal items set up and I have for instance a text input feild called ItemQuantity1

When I press the corosponding add to cart button, I want it to use the value of ItemQuantity1 to fill the variable for quantity which PayPal uses.

so if I have: |15___| |Add to cart|

when I push add to cart I want it to say that I added 15 of this item.

I tried doing

... name=quantity value=$temQuantity1

but this didnt work

Thanks

A: 

if this is a request variable (submitted via form, or otherwise put into the request), you can access this value with $_REQUEST['itemQuantity1'].

Zack
A: 

So you would start by submitting the value of the text box (itemQuantity1) to your cart handler. Once you have the data you can do the following to populate the hidden field.

<?php 
$itemQuantity = $_REQUEST['itemQuantity1'];
$itemQuantity = htmlentities($itemQuantity, ENT_QUOTES);
?>
<input type="hidden" name="quantity" value="<?php echo $itemQuantity;?>"/>

If you need to do this on the same page you can do it with JavaScript but would probably be better off just renaming the itemQuantity1 text box to quantity.

Jeff Beck
Don't forget to properly encode the $itemQuantity value before writing it to the HTML stream (can you guess what happens if $itemQuantity contains a " ?), f.i. using `htmlentities($itemQuantity, ENT_QUOTES)`
Wim
Sorry forgot I was in a hurry I'm updating the answer with this fix. Also you should do some JS validation on the form to make sure the user is entering a number but it can't be fully trusted.
Jeff Beck
How do I submit it to my cart handler?
Milo
What does you add to cart currently do?
Jeff Beck
I feel dumb, simply calling it text instead of hidden did the trick
Milo