0

In an OpenTBS situation, I'm trying to use conditional blocks to check against each individual option/answer that a user selects in a checkbox field in a form whose data is being used to insert the conditional content.

I've asked you about this previously, here Can a 'when' conditional section show content based on a 'contains' or 'includes' parameter? , and you kindly gave me a suggested solution.

Unfortunately my developers could not get it working. I wonder if there's another way. For example, can one target a specific checkbox option in a checkbox field to query whether it is checked or unchecked, using a conditional block?

Let's say I have this checkbox field in my form:

Select the kinds of personal information you collect

  • Name
  • Address
  • Phone
  • Date of birth
  • Age

Is it possible to target each choice individually with a conditional block, to check whether it has been checked/selected or not, e.g., along these lines:

[onshow;block=begin;enlarge=tbs:p;when [var.Select the kinds of personal information you collect_Name]=!'']

Name

[onshow;block=end;enlarge=tbs:p]

If this is possible, I could insert conditional content per selected option, regardless of whether other options are also selected.

Any help much appreciated. Thanks very much.

Richard

Richard
  • 1
  • 2

1 Answers1

0

It it possible and simple to use conditional blocks on paragraphs.

Here is 3 comments about your snippet :

  1. It is unwise to use block=begin and block=end in a DOCX (or other XML based documents) because we are note sure they are placed in symmetric positions relatively to the to the inner XML. It's true you are also using parameter enlarge, but there is much more simple (see below).
  2. It is good to protect the when string expression against quotes, using strconv=esc.

So a simple solution could be:

PHP :

global $collect_name, $collect_adress, $collect_phone;
$collect_name = ...;
$collect_adress= ...;
$collect_phone= ...;

DOCX :

  • [onshow;block=tbs:p;when '[var.collect_name;strconv=esc]'=!''] Name
  • [onshow;block=tbs:p;when '[var.collect_adress;strconv=esc]'=!''] Address
  • [onshow;block=tbs:p;when '[var.collect_phone;strconv=esc]'=!''] Phone
Skrol29
  • 5,402
  • 1
  • 20
  • 25
  • Thanks very much @Skrol29. Much appreciated. However, I'm not sure this will work for what I have in mind. I don't merely want to replicate the selected list item (e.g., Name) in a bullet point. Sometimes I would, but many times the selection of an item in a checkbox field will result in quite different output. That output could span multiple paragraphs, and contain hierarchical, legal-style numbering. Is there a way to achieve that please, while still targeting each checkbox item as you've done above? Thanks again. Richard. – Richard Aug 31 '19 at 04:48