0

Drupal 8.9, webforms 5.x

I'm trying to send some text data to a endpoint on form submission via a POST handler. It's based on the value of a (single) checkbox on a webform. The endpoint only accepts specific text values, so I need to somehow convert the 0/1 to those specific text values - if checked => "Signed up", else => "Not signed up".

I want the equivalent of

"key": [webform:elements:checkbox_machine_name:checked] ? "Signed up" : "Not signed up"

if you could have a ternary in the yaml format...

Is there a way I can do this via webforms?

I'm happy to install more modules, but if possible I'd like to avoid writing any PHP...

1 Answer 1

1

You could use a Computed Twig element to execute the ternary operator and set the value in the remote post data.

@see https://www.youtube.com/watch?v=rRlTTkwdP_o

2
  • This looks exactly like what I want, thanks. Am just having a little trouble getting it working though - {{ data.checkbox_name.checked ? 'Signed up' : 'Not signed up' }} seems to always evaluate to 'Not signed up'. Is anything obviously wrong?
    – LordAro
    Jun 15, 2020 at 12:50
  • I found it - .checked is not a thing. Not sure where I got that from..
    – LordAro
    Jun 15, 2020 at 14:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.