www.webdeveloper.com
Results 1 to 5 of 5

Thread: Send data with POST method w/o a field?

  1. #1
    Join Date
    Mar 2010
    Posts
    16

    Send data with POST method w/o a field?

    Hi,

    I want to add an item to a shopping cart but I don't want the url have variables in it so I have a submit button as an image that goes to shoppingCart.php How do I send the item # to the php script without another input field? Thanks

    Code:
    <form action="shoppingCart.php" method="post">
    //I want item #100 to be sent over the $_POST array. HOW???
    <input type="image" src="img/AddtoCart.png" alt= "Add to Cart"/>
    </form>

  2. #2
    Join Date
    Mar 2010
    Posts
    2,803
    I'm not sure how your cart works. Mine is a php class and I don't use POST or GET to add or delete items from it.

    POST and GET paramaters must be in the form of name=value pairs.

    I don't understand what you mean by:

    ......without another input field?

  3. #3
    Join Date
    Mar 2010
    Posts
    16
    The php generated html page(s) with all the items listed each have an add to cart button. When this button is pressed I want the item to be added to the session array and go to the shoppingCart.php. What I mean by another field is that when you are using post usually you have something like

    <input type="text" name="firstname" />

    and access the text field value by $_POST['firstname'], I want to send the item number (which I already know) to the shoppingCart.php page without using any text fields or anything so how would I get item#100 into the $_POST array? Thanks.

  4. #4
    Join Date
    Mar 2010
    Posts
    16
    Figured it out. It was simpler than I thought

    Code:
    <form action="shoppingCart.php" method="post">
    <input type="image" src="img/AddtoCart.png" alt= "Add to Cart" name = "item_ID" value = "1"/>
    </form>
    Is this a bad idea, sending a form for an add to cart operation? I want to keep the url clean of any variables. What are the pros and cons of using post for this type of operation? Thanks

  5. #5
    Join Date
    Mar 2010
    Posts
    2,803
    I don't use post or get to interact with my cart, but regardless of how you interact with your cart one of the most important things you need to ensure is that shoppers can't manipulate the prices and/or quantities in the cart by 'hacking' or some vulnerability in your code in the hope to get something for free.

    Make sure you validate thoroughly any data being passed to your cart and that the code doesn't allow illegitimate changes to the items, prices and quantities.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles