Unchecked checkbox on form is setting values to false/no

Megan_Koelemay
Level 4

Unchecked checkbox on form is setting values to false/no

We have a form on our website where people can download gated content.  On this form, they can also choose to opt in to our email list.  This is presented as a checkbox, and when it's checked, the person's opt-in field is set to true/yes.  

 

But if the checkbox is unchecked, any existing data on the opt-in field is overwritten with a false/no value.  This means people who were already opted into our email list and submit the form with the checkbox unchecked are getting opted out. 

 

We want to make it work so this field is not overwritten or modified in any way if the checkbox is unchecked.  Is that possible?  I actually thought Marketo forms were already supposed to work this way, but my testing is telling me otherwise.

7 REPLIES 7
Katja_Keesom
Level 10 - Community Advisor + Adobe Champion

Re: Unchecked checkbox on form is setting values to false/no

Hi Megan,

Indeed, a checkbox on a form behaves in a very binary way, so it is true or it is false and nothing in the middle.

I have achieved what you are looking for in different variations using a second "mirror" field for the Opt-in checkbox. A few ways in which you could use this:

  • Add the mirror field as hidden field on your form and add a visibility rule to the Opt-in checkbox to only show if the mirror field is set to false. That way, your lead does not even see the checkbox if they already opted in before.
  • Simply use the mirror field visibly on the form and let the real Opt-in field update or not depending on what happens with the mirror field.

I'm sure there are other ways to achieve this as well, but these have always delivered reliable results. Hope it helps.

SanfordWhiteman
Level 10 - Community Moderator

Re: Unchecked checkbox on form is setting values to false/no

Like Katja says, this is longtime Marketo behavior.

 

There's good reason (until you're familiar with Marketo's implementation, of course!) to expect that an unchecked <input type="checkbox"> will not be posted to Marketo at all, because pure HTML forms do work this way.

 

In a vanilla HTML form, an unchecked checkbox is skipped and not sent to the server. There's also no 3rd state: the field is either (1) unchecked = not sent to the server or (2) checked = sent to the server with the current field name and value. The HTML5 standard even remarks about it only having 2 states:

 

2021-02-10 01_57_01-4.10 Forms — HTML5.png

 

On a Marketo form, the standard Checkbox also only has 2 possible states. But they're not the same 2 states. In Marketo, the field is either (1) unchecked = sent to the server as "no" or (2) checked = sent to the server as "yes".

 

As you can see, there are 3, let's say "interesting" things that a checkbox can mean in general, but on any given form it can only mean 2 of those 3 things.

 

There's an interesting solution that avoids the need for the proxy field as Katja mentions (though that would also work). You need to use the Checkboxes field type, not Checkbox, but with only a single checkbox. And set the value of the checkbox to

 

 

truthy

 

 

that's the string "truthy" with no quotes.

 

Then the value will be updated to true if the checkbox is checked, but otherwise ignored. However, if you do use this method, note that standard Form Pre-Fill will then not work on its own, that is, the checkbox won't be pre-checked — you'd need a line or two of JS to fix that up.

Dave_Roberts
Level 10

Re: Unchecked checkbox on form is setting values to false/no

Here's a bit on using the "checkboxes" input rather than the "checkbox" input if you do decide to go that route:

https://nation.marketo.com/t5/Product-Blogs/Form-styling-How-to-position-checkbox-labels-to-the-righ...

Michael_Florin
Level 10

Re: Unchecked checkbox on form is setting values to false/no


We want to make it work so this field is not overwritten or modified in any way if the checkbox is unchecked.  


So for already opted-in persons you want to make the checkbox meaningless. Regardless what they do, they stay opted in. That doesn't make much sense, does it? Why do you show them the checkbox then?

 

Yes, I know, this is a legal question, and who wants to tread on that territory? But I personally don't like the way these check-boxes are treated. Show them - unchecked - for the unknown person and hide them for the known person. "Known" pretty much equals "opted in" here, because the box can only be hidden if they click through from a Marketo email, so they must be subscribed.

SanfordWhiteman
Level 10 - Community Moderator

Re: Unchecked checkbox on form is setting values to false/no

The field could be dynamically shown via ProgPro, which works even if you don't follow a link (or even on a non-Marketo page).

Plus an email could be operational but have a link to the Pref Ctr.

So it's not as simple as known session = checkbox must already be checked.
Megan_Koelemay
Level 4

Re: Unchecked checkbox on form is setting values to false/no

There are some great, creative solutions in these replies!  Thanks all!  

 

We ended up going another direction - our developer discovered that if we set the field type to "text" instead of "checkbox," blank values won't submit anything to the server.  We're able to keep the checkbox "look" because we style our own customer-facing form and hide the Marketo form behind it (our form passes the data to the Marketo form first, which then submits to Marketo).  

 

So far it seems to be working: An unchecked checkbox (technically, a blank text field) won't submit anything and therefore won't override any existing data with a no/false value, and a checked checkbox (technically a text field populated with a "true" value) sets the field in Marketo to true.

SanfordWhiteman
Level 10 - Community Moderator

Re: Unchecked checkbox on form is setting values to false/no

But if you're using a hidden Marketo form (shoulda mentioned that!) you don't need the field to be on the form at all.

 

You just add it with addHiddenFields. And if you don't add it, it won't exist at all on the Marketo form, and therefore there's no chance it'll update Marketo.

 

P.S. For clarification, this isn't exactly true:


...  if we set the field type to "text" instead of "checkbox," blank values won't submit anything to the server.

In fact a blank Text field does submit something. It submits an empty string, and the server ignores it. But it is sent to the server over the network.