News:

Support the VirtueMart project and become a member

Main Menu

Required checkbox cannot be checked in the cart

Started by at, May 19, 2018, 16:15:11 PM

Previous topic - Next topic

at

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

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

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

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

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:

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

Hi,

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


/**
* 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

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

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/