checkbox not validating
-
A checkbox with required attribute as well as the GDPR form element do not validate when checked.
Steps to reproduce in Formello 2.2.2:
- Create a new contact form
- Add GDPR to the contact form
- Publish it
- Add the contact form to a new page an try it out.
-
Can you check if latest update solve this problem?
No, it didn’t solve the problem. Here is the markup of the gdpr block used:
<!-- wp:formello/input {"advanced":false} --> <div class="formello formello-checkbox"><label class="" for="field_99ef3d"><span>Ich stimme zu</span><span class="required">*</span></label><input name="checkbox" id="field_99ef3d" type="checkbox" required class=""/></div> <!-- /wp:formello/input -->And here ist the markup for the enclosing form block:
<!-- wp:formello/form {"successMessage":"Vielen Dank! Ihre Bestellung wurde gesendet.","errorMessage":"Entschuldigung. Ihre Eingaben sind noch nicht komplett.","lock":{"move":false,"remove":false},"className":"as-row","style":{"spacing":{"padding":{"top":"0","right":"0","bottom":"0","left":"0"}}}} --> <form class="wp-block-formello-form as-row" style="padding-top:0;padding-right:0;padding-bottom:0;padding-left:0" method="post" data-id="151" data-hide="true" data-validate="true" novalidate>Moreover after removing the checkbox block, the form does not submit anymore in Formello 2.3.1, outputting
SyntaxError: Unexpected token '<', " Es gab "... is not valid JSONCan you share a live link?
No, I cannot share a link, since the website is in production and I have to roll back immediately.
However, I noticed that you provided another update (2.3.2). I performed the update again, had the same problem with a checked checkbox not validating, but the json error after removing the checkbox block is gone.
So I am on 2.3.2 now without a checkbox.
Can you try to set a value for checkbox?
Yes, that’s it – the missing value. With JavaScript validation enabled, the form does not validate without a value for the checkbox. As soon as I set “on” as a value it worked.
However, with JavaScipt validation disabled and HTML5 validation only, the form validates even without a value. And that’s how it’s supposed to work since the HTML spec says that if a checkbox name is submitted with empty value the default value should be “on”.
So I suggest that you rework the JS validation in Formello and make empty checkboxes validate with “on” as default value.
Thanks for your support!
I have made some changes to 2.3.3 that perform exactly what you are saying. So this is solved.
The only differences is that I set “yes” as default value instead on “on” if value is missing.
I’d probably add a setting to let user choose what is default. What are you thoughts?This is solved. Let me know if you nedd further assistance. Thanks
Sorry for the late reply. I thought about setting a default value or not, and came to the conclusion, that it might be the safest not to set any default – neither “yes” nor “on” – but perform the JS validation in a way where a checkbox, that is checked but has no value, is validating – like it does with HTML5 validation. That way, you are following the standard, and at the same time, your don’t have to make up a value or ask the Formello user to set one, because a value is not necessary.
For reference:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox#value
The topic ‘checkbox not validating’ is closed to new replies.