Results 1 to 6 of 6
  1. #1
    Join Date
    Dec 2011
    Posts
    44
    Plugin Contributions
    0

    Default Passing values between pages - Confused

    Can anyone please help me to better understand how parameters are passed between pages?

    The example I'm looking at is adding a product to the shopping cart from a product page.

    On the Product Page, the HTML form behind the “Add to Cart” button (as shown in View Source) shows the Action as:

    Code:
    <form name="cart_quantity" action="http://example.com/index.php?main_page=product_info&amp;cPath=0&amp;products_id=34&amp;action=add_product" method="post" enctype="multipart/form-data"><input type="hidden" name="securityToken" value="2d9dd751a811a5be15fe2f053a2ae3b9" />
    This says three things to me:
    • The method for transferring data is POST
    • The 'action' value being passed is “add_product”
    • The products_id (for identifying the product) is being passed.

    I would therefore have expected a POST array to be picked up by a PHP script and used to progress the shopping cart process. However, I can't seem to work out how this happens.

    My testing seems to show that the array of data is received in 'init_cart_handler.php', specifically in the “if (isset($_GET['action'])) {” conditional loop. I say this because I traced the shopping cart functionality back through 'shopping_cart.php' to 'main_cart_actions.php' to 'init_cart_handler.php'.

    But by the time the array has made it through to 'shopping_cart.php', it is being referred to as a POST array.


    The reason I ask is because I am altering the visible URLs using .htaccess re-writes. According to Apache logs, an “un-rewritten” URL is received as follows:
    blah...
    Request:
    Code:
    "POST /index.php?main_page=product_info&cPath=0&products_id=34&action=add_product HTTP/1.1"
    ...blah...
    Referrer:
    Code:
    "http://example.com/index.php?main_page=product_info&cPath=0&products_id=34"
    ...blah

    whereas the re-written URL is received as:

    blah...
    Request:
    Code:
    "POST /index.php?main_page=product_info&cPath=0&products_id=34&action=add_product HTTP/1.1"
    ...blah...
    Referrer:
    Code:
    "http://example.com/A-product-name"
    ...blah

    The Request is the same. Only the referrer is different, yet one successfully initiates a purchase and the other just reloads the same page. This is where I'm confused. With no difference in the POST string being received by the server, why are the two requests being treated differently?


    Can anyone help me to understand the mechanics here please?


    PS:
    v1.5.1
    No mods
    No Apache errors
    No “myDEBUG...” errors.

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,965
    Plugin Contributions
    96

    Default Re: Passing values between pages - Confused

    Quote Originally Posted by Earthenware View Post
    Can anyone please help me to better understand how parameters are passed between pages?

    The example I'm looking at is adding a product to the shopping cart from a product page.

    On the Product Page, the HTML form behind the “Add to Cart” button (as shown in View Source) shows the Action as:

    Code:
    <form name="cart_quantity" action="http://example.com/index.php?main_page=product_info&cPath=0&products_id=34&action=add_product" method="post" enctype="multipart/form-data"><input type="hidden" name="securityToken" value="2d9dd751a811a5be15fe2f053a2ae3b9" />
    This says three things to me:
    • The method for transferring data is POST
    • The 'action' value being passed is “add_product”
    • The products_id (for identifying the product) is being passed.

    I would therefore have expected a POST array to be picked up by a PHP script and used to progress the shopping cart process. However, I can't seem to work out how this happens.

    My testing seems to show that the array of data is received in 'init_cart_handler.php', specifically in the “if (isset($_GET['action'])) {” conditional loop. I say this because I traced the shopping cart functionality back through 'shopping_cart.php' to 'main_cart_actions.php' to 'init_cart_handler.php'.

    But by the time the array has made it through to 'shopping_cart.php', it is being referred to as a POST array. ...
    Like you've found, the variable that starts a cart-processing action is $_GET['action'] which is first intercepted by /includes/init_includes/init_cart_handler.php. That script next loads any .php files present in the /includes/extra_cart_actions folder, where cart-related overrides can be coded. Next loaded is /includes/main_cart_actions.php, which routes specific values (like add_product) for the $_GET['action'] variable to their associated functions within the session's shoppingCart object.

    When you inspect the HTML associated with the add-to-cart form, you'll see hidden input variables that contain the product_id and (optionally) attribute values; those are the POST variables that are processed by the shopping_cart class.

  3. #3
    Join Date
    Dec 2011
    Posts
    44
    Plugin Contributions
    0

    Default Re: Passing values between pages - Confused

    That's helpful, thanks.

    I'm still a little confused though. Perhaps my knowledge of HTTP is lacking.

    1/ Why is the content of a method="post" received by a $_GET? I didn't think the two methods were interchangeable and I would have expected to see a $_POST in init_cart_handler.php.

    2/ I don't understand what difference this makes to the transmission of the parameters to the next script. The HTTP request is identical in both examples I gave, only the referrer is different.

    Apologies if I am missing somehting obvious.

  4. #4
    Join Date
    Feb 2012
    Location
    mostly harmless
    Posts
    1,809
    Plugin Contributions
    8

    Default Re: Passing values between pages - Confused

    Quote Originally Posted by Earthenware View Post
    ... The reason I ask is because I am altering the visible URLs using .htaccess re-writes. ...
    One cannot change the visible URLs (in HTML) using .htaccess rewrites... I hope you are not trying to "change" Zen Cart URLs by simply using redirects (via mod_rewrite) inside a .htaccess file. If you are this will cause you lots and lots of headaches...

    The better way of altering the Zen Cart URLs is to change the way Zen Cart builds the URL for display. This results in the correct URL being placed directly in the generated HTML. CEON URI Mapping, Ultimate URLs, and Simple SEO URLs all use this method (along with actual rewrites - not redirects).
    The glass is not half full. The glass is not half empty. The glass is simply too big!
    Where are the Zen Cart Debug Logs? Where are the HTTP 500 / Server Error Logs?
    Zen Cart related projects maintained by lhûngîl : Plugin / Module Tracker

  5. #5
    Join Date
    Dec 2011
    Posts
    44
    Plugin Contributions
    0

    Default Re: Passing values between pages - Confused

    Ok, I've tried to work this out and what I think is happening is this:

    • A request to add a product to a cart is received by init_cart_handler.php.
    • If there is a parameter $_GET['action'], init_cart_handler.php calls main_cart_actions.php.
    • Main_cart_actions.php evaluates the $_GET['action'] and if the value is 'add_product', it calls the actionAddProduct' function, which is contained in shopping_cart.php.
    • Once shopping_cart.php is dealing with the request, it used the $_POST array.

    Assuming that I'm not talking nonsense, this would explain why a URL re-write that doesn't contain “action=add_product” (or something similar, I haven't tested it) doesn't work, despite the Apache access log recording a correct POST string.

    Can anyone confirm please?

  6. #6
    Join Date
    Dec 2011
    Posts
    44
    Plugin Contributions
    0

    Default Re: Passing values between pages - Confused

    Quote Originally Posted by lhungil View Post
    If you are this will cause you lots and lots of headaches...
    Yes, I can see why now.

 

 

Similar Threads

  1. v151 My "Options" values aren't passing to Paypal (payment Pro )
    By johnny1114 in forum PayPal Website Payments Pro support
    Replies: 2
    Last Post: 20 Aug 2015, 02:22 PM
  2. Passing values from another page...
    By JPrescott in forum General Questions
    Replies: 2
    Last Post: 3 Oct 2011, 06:05 PM
  3. What is the diference between ez-pages and define pages?
    By jojo_cool in forum General Questions
    Replies: 2
    Last Post: 3 Jul 2009, 08:00 PM
  4. Confused by EZ Pages and Define Pages
    By Seanmyr in forum Templates, Stylesheets, Page Layout
    Replies: 4
    Last Post: 10 Apr 2008, 09:15 PM
  5. By Passing Check-Out Pages?
    By aquestioner in forum General Questions
    Replies: 0
    Last Post: 1 Dec 2007, 02:54 PM

Posting Permissions

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