I have a single checkbox in a Formit Form that I have built within the Zurb Foundation framework. When the form submits… the result in the response email is either “on” or “off”. Is there a way to set this up such that if the box is checked, the result is YES, or if unchecked the result would be NO.
<fieldset class="fieldset">
<legend>OPT-IN</legend>
<input name="checkboxOptIn" id="checkboxOptIn" type="checkbox"[[!+fi.checkboxOptIn:FormItIsChecked=`yes`]] ><label for="checkboxOptIn">Add me to your mailing list.</label>
</fieldset>
Thank you for your prompt feedback. I do have that placeholder in my email chunk. Maybe I need a value… like I do on my radio selects. Just not sure how the two values of YES & NO get applied to the checkbox. In reality, the only result I need is when the box is checked… the result insert the email, and DB is is a YES.
I have discovered that if I insert value=“Yes” into the code for the checkbox… and the box gets checked, the result is “Yes” in the email. However, if the box is not checked, the result is the placeholder [[+checkboxOptIn]].
Perhaps I need to include also include something like this? [[!+fi.checkboxOptIn:FormItIsNotChecked=no]]
But I don’t understand how it determines what value. Or perhaps a value is not necessary?
You could use a placeholder like [[+checkboxOptIn:default=`No`]].
This outputs the value “No” if the placeholder is missing or empty.
Alternatively (to fix the issue directly in HTML), you could add a hidden input field to the HTML form with the same name as the checkbox. Something like this:
This scenario is not working. <input name="checkboxOptIn" id="checkboxOptIn" type="checkbox" value="Yes" [[!+fi.checkboxOptIn:FormItIsChecked=Yes]] [[+checkboxOptIn:default=No]]>
When checked the result in the email = Yes
When unchecked, the result in the email is still = [[+checkboxOptIn]]
Thank you! I am giving this a try. But also now trying to set the default of the checkbox as being checked.
Using the attribute “checked” set the box default to be checked. Still testing results when form is submitted.
value=“Yes” checked
I finding as well that the Recatpcha creates many issues. If a visitor attempts to hit send without performing the recaptcha, then any select items —checkbox, or radios go to default settings… yet that seems to be only the visual display onscreen… .while the checked or unchecked states do actually transfer to the email, and the formit database. For now I may just remove that Recaptcha V2. more trouble than it’s worth. It was generating tons and tons of errors, and that alone I was able to resolve with assistance from SepiaRiver.
Below is current code for the checkbox that “does” have the checkbox “checked” by default — and when left checked, the result is “Yes”
However, if the box is unchecked, the result in the email is [[+checkboxOptIn]]
Still trying to understand how to get an unchecked box to insert “No” into the email rather than [[+checkboxOptIn]]
<div class="grid-x grid-padding-x">
<div class="cell">
<fieldset class="fieldset">
<legend>MARKETING OPT-IN</legend>
<input name="checkboxOptIn" id="checkboxOptIn" type="checkbox" value="Yes" checked [[!+fi.checkboxOptIn:FormItIsChecked=`Yes`]]><label for="checkboxOptIn">Please put me on the insider email list.</label>
</fieldset>
</div>
</div>
Did you try Harry’s first suggestion to put an output modifier on the placeholder in your email template?
Something like: [[+checkboxOptIn:notempty=`[[+checkboxOptIn]]`]]
That should print the value of the checked checkbox, which you have set to “Yes”, or nothing if the checkbox is not checked.
Or, if you specifically want it to print “No” when unchecked, something like this would work: [[+checkboxOptIn:notempty=`[[+checkboxOptIn]]`:else=`No`]]
It’s useful to remember that a checkbox only has a value when checked. It doesn’t have two values; a checked value and an unchecked value. So there is no way that I know of to pass a value of an unchecked checkbox because it’s just an empty input. That’s why the notempty conditional works.
Disclaimer: those output modifiers are untested and I’m posting this on a Saturday night, so if they don’t work out of the gate just look for typos.
Thank you for this very helpful and informative feedback. I have tested both output modifiers, and when the box is not checked, the result in the email is still [[+checkboxOptIn]]. I am giving everything a thorough review again.
This gives me “Yes” when checked, but nothing when not checked—which is OK. Not sure why a “No” does not get inserted, but continuing to experiment.
Is if possible that you cannot do the double placeholder. Maybe I try removing the placeholder on notempty, and actually insert Yes. Will continue to experiement. But for now, having a yes is good, and nothing with not checked, helps make it user friendly.
Did you try Harry’s suggestion of setting the email placeholder with default empty output of No? [[+checkboxOptIn:default=`No`]]
That really should work. If the checkbox is not checked, the placeholder is empty so it prints No. If the checkbox is checked, there is a value so it prints the value, which you have set to Yes.
If you did try this previously and it didn’t work, make sure you are not adding the checked attribute to the checkbox input HTML.
I put Harry’s suggested [[+checkboxOptIn:default=No]]
into the email and yahoo! Got a “NO” when the box was left unchecked.
However… now, when the box is checked I get a YES YES… as in a double yes.
<fieldset class="fieldset">
<legend>MARKETING OPT-IN</legend>
<input name="checkboxOptIn" id="checkboxOptIn" type="checkbox" value="Yes" checked [[!+fi.checkboxOptIn:FormItIsChecked=`Yes`]]><label for="checkboxOptIn">Please put me on the insider email list.</label>
</fieldset>
In the form:
<input type=“hidden” name=king" value=“no”>
<input type=“checkbox” class=“form-check” name=“king” value=“yes” [[!+fi.king:FormItIsChecked=yes]]> in the email template:
King: [[+king:default=`No`]]
Used multiple times in multiple projects, if not checked you get No if checked you get Yes.