Forums

Display/Hide a field when multi checkbox is checked/unchecked

deltafidesign 20 Feb, 2016
Hi,

I have a multi checkbox field that contains only one option. I use it to let users subscribe to acymailing newsletter, that option is the newsletter list ID. In my case I have just one list, so that field just show one option but it must be a multi checkbox because in that way I can let it work with the acymailing subscribe process (don't remember why, but should be a post on the forum somewhere that explains how to)

If users choose that option (subscribe to the newsletter) I need to show/hide another field (a radio button).
I've setted the radio button as "parent hidden", then I've setted the multi check box field with 2 events:
1) if = 1 (where 1 is the value of the first and only option) => showparent (radio field)
2) if != 1 => hideparent (radio field)

In this case when I check the option then the radio button is displayed but when I uncheck the option the radio button is not hidden

What's wrong? How should I do it?

Thanks in advance.
GreyHead 20 Feb, 2016
Hi deltafidesign,

The built in events don't work well with CheckBox groups - It can't work out what is checked and what isn't. You can use a radio button for this or write custom code to handle it.

Bob
deltafidesign 20 Feb, 2016
Hi Bob,

thanks for reply. Could you suggest me the code I should use? I cannot use a radio button.

Thanks in advance.
GreyHead 20 Feb, 2016
Hi deltafidesign,

You can use a radio button - or a single checkbox and use a Custom Code action after the form submits to convert the data into the format you need for AcyMailing.

Bob
deltafidesign 20 Feb, 2016
Hi bob,

I'm a bit confused. I don't really know what to do and what code should I write (I'm not able also to write such code... :-) )

Would you help me step by step also providing the code?
GreyHead 21 Feb, 2016
HI deltafidesing,

I'd use a single checkbox with the name say 'sign_up' with the Field value yes and Ghost value no

In the On Submit event add an Event Switcher action with one event yes; add the cURL or ACY Subscribe [GH] action to the yes event of the Event Switcher. In the Event Switcher add the code:
<?php
return $form->data['sign_up'];
?>

Bob
deltafidesign 01 Mar, 2016
Hi Bob, thanks for reply but I would keep the multi check box field. I would let the user the ability to choose one or more acymailing list at the same time even if at the moment I use only one list.

Any other solution? Javascript?
GreyHead 01 Mar, 2016
Hi deltafidesign,

No JavaScript needed, In the Event Switcher check to see if there are any entries in the data array from the CheckBox Group.

Bob
This topic is locked and no more replies can be posted.