Author Topic: Required checkbox cannot be checked in the cart  (Read 2301 times)

at

  • Beginner
  • *
  • Posts: 10
  • A beginner
Required checkbox cannot be checked in the cart
« on: May 19, 2018, 16:15:11 pm »
I defined a shopper field of type single checkbox. I made it required, published, shown in cart form and shown in shipment form. Basically, the text near the checkbox is related to GDPR, so I must leave it unchecked and proceed to checkout only after the user checks it.

I use the standard VM's OPC and Ajax for OPC is enabled. I run the latest VM 3 on the latest Joomla.

As a customer, I put some products in the cart, enter the required shipment data and choose shipment and payment options. However, when I try to check the checkbox, it stays checked for a second but then it automatically becomes unchecked. So the user effectively will not be able to checkout.

The checkbox remains checked if I remove "Ajax for OPC" in VM config, but I really need Ajax to be there. The checkbox also behaves correctly if I set its default value to 1, but GDPR says I can't do that and the user must put a tick himself.

What should I do in this case?

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3479
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Required checkbox cannot be checked in the cart
« Reply #1 on: May 19, 2018, 19:36:07 pm »
This looks like a JS problem. Test if unpublish ALL shipments and payments plugins exept standard shipment and payment resolves the issue. A badly written payment or shipment plugin can break this funtionality.

And please
http://forum.virtuemart.net/index.php?topic=79799.0

regards

Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

at

  • Beginner
  • *
  • Posts: 10
  • A beginner
Re: Required checkbox cannot be checked in the cart
« Reply #2 on: May 19, 2018, 20:27:17 pm »
Thank you Jorgen.

I unpublished all payment and shipment plugins, but it didn't help. It seems that the form is submitted when I check this checkbox (at least it seems so in Chrome). As this doesn't happen when I disable Ajax in VM OPC, I think I'm right. But the fact that the field represented by this checkbox was changed isn't saved in the session, so after reload of the form the check disappears.

I'm really curious why the tick doesn't disappear if I set the field's default value to 1, then remove the tick in the FE, and then put it back. The tick stays there as it should.

Sorry for not mentioning the versions. I'm on VM 3.2.14, Joomla 3.8.7 and PHP 7.1.17. I'm using the Furniturestore template from virtuemarttemplates.net.

Jörgen

  • Global Moderator
  • Sr. Member
  • *
  • Posts: 3479
    • Kreativ Fotografi
  • VirtueMart Version: 3.4.x
Re: Required checkbox cannot be checked in the cart
« Reply #3 on: May 20, 2018, 10:18:24 am »
You could check a couple of things. Does the standard TOS check box have the same behaviour ? You can also check how it behaves with the protostar template.
Regards
Jörgen @ Kreativ Fotografi
Joomla 3.9.18
Virtuemart 3.4.x
Olympiantheme Hera (customized)
This reflects current status when viewing old post.

at

  • Beginner
  • *
  • Posts: 10
  • A beginner
Re: Required checkbox cannot be checked in the cart
« Reply #4 on: May 20, 2018, 11:01:57 am »
I checked a couple of things.

1. If my GDPR checkbox has no default value, then I can't put a tick there, so it doesn't allow to checkout.

2. If my GDPR checkbox has default = 1, then I can remove a tick and put it again, it stays there. However, if I click on the Checkout Now button, the site complains that the value of the GDPR checkbox is missing (regardless if there is a tick or not).

3. If I use the default TOS, which is checked by default, everything is fine. I can checkout if there is a tick.

4. If I use the default TOS but modify the tos.php so that the checkbox is WITHOUT a tick (see the code below), then, on the click of the Checkout button, it complains that I didn't check the checkbox, whether it was actually checked or not. Here's the modification:

Code: [Select]
echo VmHtml::checkbox ($_prefix.$field['name'], $tos, 0, 0, 'class="'.$class.'"', 'tos');
All these things happen regardless of the template. I checked it on the beez3 template, the behavior is the same.

panjarek

  • Beginner
  • *
  • Posts: 23
  • A beginner
Re: Required checkbox cannot be checked in the cart
« Reply #5 on: August 17, 2018, 09:36:48 am »
Hi,

Maybe you have to set $checkedValue to '1', the method hes following parameters:

Code: [Select]
/**
 * Generate HTML code for a checkbox
 *
 * @param string Name for the checkbox
 * @param mixed Current value of the checkbox
 * @param mixed Value to assign when checkbox is checked
 * @param mixed Value to assign when checkbox is not checked
 * @return string HTML code for checkbox
 */
static function checkbox($name, $value, $checkedValue=1, $uncheckedValue=0, $extraAttribs = '', $id = null)

at

  • Beginner
  • *
  • Posts: 10
  • A beginner
Re: Required checkbox cannot be checked in the cart
« Reply #6 on: August 18, 2018, 21:07:18 pm »
Thanks for suggestion, I tried it already, it didn't help at that time.

Now it's working.. generally, using the workaround of setting up the text near the TOS checkbox to tell the user about GDPR. As was described in a post that somehow disappeared from this thread, the TOS checkbox works correctly only after the user specified the addresses, shipment method and payment method. Otherwise, the behavior of the checkbox is very strange. As we have a one-page checkout layout, the user can easily click the checkbox whenever he wants, sometimes leading to problems. We had only one complaint regarding this in the past months, though.

I don't try to experiment with this anymore :) Just happy to get it working at least this way. I believe, the php code should disable the checkbox at all if addresses or shipment method or payment method are undefined, but haven't implemented it yet.

Milbo

  • Virtuemart Projectleader
  • Administrator
  • Super Hero
  • *
  • Posts: 10094
  • VM3.2 Cached and Optimized
    • VM3 Extensions
  • VirtueMart Version: VirtueMart 3 on joomla 3
Re: Required checkbox cannot be checked in the cart
« Reply #7 on: August 20, 2018, 13:12:52 pm »
Please use this version http://dev.virtuemart.net/attachments/download/1124/com_virtuemart.3.2.15.9910_package_or_extract.zip and the sublayout tos2 and work on that one.
I should fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/