Discovered a curious bug and not sure if this is UC or Drupal related. If comments are enable for the product content type and an user submits a comment and then clicks the "Preview" button on the comment form they are then taken to the preview page. Now if they click "submit", instead of the comment being submitted the product is added to the users cart.
I'm not sure if this was the case in D6?/UC2 but I did use comments on one site and didn't see this.
You can test it out here http://dev.ubercartdemo.com/node/1
login details
User: comment
Pass: comment
I tested this with Garland and Bartik. At first I thought it was my theme that was the issue but not so.
Comment | File | Size | Author |
---|---|---|---|
#8 | 1800626-comment-preview-submit.patch | 1.39 KB | longwave |
#2 | 1800626-comment-preview-submit.patch | 1.49 KB | longwave |
Comments
Comment #1
longwaveBug confirmed, only occurs when previewing a comment, seemingly due to the add to cart form effectively being embedded inside the comment save/preview form, and the former apparently overrides the latter.
Comment #2
longwaveNot sure this is the correct approach, but it seems to work after very basic testing.
Comment #3
longwaveAn alternative might be to move the add to cart form from uc_product_view() to hook_entity_prepare_view().
Comment #4
end user CreditAttribution: end user commentedTested it out and seems to work good.
Comment #5
longwaveCommitted #2.
Comment #7
longwaveReopening, as this change caused various issues with Panels and Views.
Comment #8
longwaveThis doesn't seem as clean, but I don't see any other way to detect the comment reply page.
Comment #9
DanZ CreditAttribution: DanZ commentedAre comments the only place where this mix-up could happen?
I haven't looked into the code, but it seems like the add-to-cart button ought to work in some way that doesn't interfere with the main form on a page.
Comment #10
end user CreditAttribution: end user commentedIt interferes with VBO also.
Comment #11
longwaveUnfortunately, this and the VBO issue are due to the way Drupal builds up pieces of content by wrapping smaller pieces in bigger pieces of HTML. In cases involving multiple forms such as these, the add to cart form gets wrapped up inside the comment reply form and the VBO action form - but nested <form> tags are not allowed by the HTML spec and therefore they present broken behaviour. However, there is not enough context passed into the add to cart form to be able to tell whether it is being rendered inside a comment reply form, VBO form, etc. so it appears the only way of handling this is on a case by case basis.
Therefore, it looks like the only reliable way of detecting a comment reply form is with the URL /comment/reply. The VBO issue will have to be dealt with separately, probably in a Views hook or plugin somehow, as we cannot detect this from the URL alone.
Comment #12
longwaveCore issue: #1323656: The comment preview form doesn't account for nodes that already contain a form
Comment #13
longwaveCommitted #8.
The VBO issue cannot be handled the same way, and will be dealt with in #1835206: VBO add to cart does not work with Add To Cart/Buy Now fields