Join the Webstudio community

Updated 3 months ago

Form checkbox

At a glance

The community member has a form with a checkbox and wants to retrieve its value. When the checkbox is checked, the value is "on", but when it's unchecked, the value is not sent. The community member has two questions:

1. Is it possible to get a true or false value instead of "on" or "off"?

2. Why is the checkbox value not sent when the checkbox is unchecked?

The comments suggest that this is how checkboxes work - they either send a value or omit it. The community members are advised to use radio buttons instead if they want a true/false value. However, on the backend, they can coalesce the missing value with a default one.

There is no explicitly marked answer in the comments.

Hi guys

Here is my form and I've got a checkbox. I want to retreive the value of the checkbox. You've got my config in attachment.

When I test it with a webhook (on webhook.site), here is what I've got :
  • When it's check I've got terms-checkbox="on"
  • When it's NOT check I cannot retreive the value (who should be "off" ?)
So I've got 2 questions:

1/ I would prefer to get true or false when it's check or not. Do you know if it's possible to have theses value rather "on" or "off"?

2/ When the checkbox is NOT fill and I press submit, the checkbox value is not send. Do you know why?

Thanks a lot πŸ™‚
Attachment
SCR-20241102-lpdt.png
B
M
J
5 comments
This is how checkbox works, either sends value or omits it. What you want is radio with two options. Though it is tricky to style as singular control.
Though on backend you can always coalesce missing value with default one.
ok @TrySound. thanks a lot. I didn't know about that! I learnt something πŸ™‚

Next time I will check the MDN page which is pretty clear about my question. Sorry for that and thanks!
With react framework we forget about this too every time πŸ™‚
I ran into this years ago and found something that didn't make sense to me. Inspect a checkbox with your dev tools. Check them on and off. You'll see no difference.

I completely forget why it's this way or the solution. Just pointing out a possible reason... πŸ˜›
Add a reply
Sign up and join the conversation on Discord