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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

longwave’s picture

Title: Drupal comments form conflicts with UC add to cart form » Drupal comment preview conflicts with add to cart form

Bug 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.

longwave’s picture

Version: 7.x-3.1 » 7.x-3.x-dev
Status: Active » Needs review
FileSize
1.49 KB

Not sure this is the correct approach, but it seems to work after very basic testing.

longwave’s picture

An alternative might be to move the add to cart form from uc_product_view() to hook_entity_prepare_view().

end user’s picture

Tested it out and seems to work good.

longwave’s picture

Status: Needs review » Fixed

Committed #2.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

longwave’s picture

Status: Closed (fixed) » Active

Reopening, as this change caused various issues with Panels and Views.

longwave’s picture

Status: Active » Needs review
FileSize
1.39 KB

This doesn't seem as clean, but I don't see any other way to detect the comment reply page.

DanZ’s picture

Are 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.

end user’s picture

It interferes with VBO also.

longwave’s picture

Unfortunately, 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.

longwave’s picture

longwave’s picture

Status: Needs review » Fixed

Committed #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

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.