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.
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:
I'm sure there are other ways to achieve this as well, but these have always delivered reliable results. Hope it helps.
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:
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.
Here's a bit on using the "checkboxes" input rather than the "checkbox" input if you do decide to go that route:
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.
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.
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.