Results 1 to 4 of 4

Thread: Access post array value programmically

  1. #1
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default Access post array value programmically

    I have this shopping cart that has one one form with multiple buttons and multiple test field all having name generated dynamically using the product id. How can i automatically access the post array value when some click the add to cart button if i dont know the names becuase each have an product id prepended to it.
    i saw this and tried for days but no result

    $values = print_r($_POST,true); //without set to true it shows variable names and values.

    i have been trying to access the values from the $value variable by doing a for loop but no luck. any one can tell me the best way to do this. This would have been a breeze but form elements are really generated using javascript(which i hardly know) so its harder for me to find solution, that is why i was just wondering if the add to cart button is clicked, i can access all the values of the $_POSt array, then i can figure which one has a value (ie the value that they placed in the text box) to send it to the database.
    "...men are that they might have joy."
    Nephi

  2. #2
    Join Date
    Feb 2003
    Posts
    3,184
    Rep Power
    0

    Default

    sounds like you are hack something together (which is usually not a good idea). But I think it may be easier if you do a for loop through the post array;
    Code:
    foreach($_POST as $key=>$value){
     print($key.' - ' .$value . '<br />');
    }
    then check the key/value for what you are looking for. Grouping the form field together using array syntax will help as well.

  3. #3
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    Thanks very much for your response. I will give it a try.
    "...men are that they might have joy."
    Nephi

  4. #4
    Join Date
    May 2004
    Posts
    530
    Rep Power
    0

    Default

    Thanks a million it worked great.
    "...men are that they might have joy."
    Nephi

Posting Permissions

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