how to sanitize checkbox input?

Be sure to set the value in your markup. You should have.

<input type="checkbox" name="changeposition" value="yes" />

Then, I’d suggest using sanitize_key() to sanitize.

Keys are used as internal identifiers. Lowercase alphanumeric
characters, dashes and underscores are allowed.

Think of the word yes, as a key. That’s what you’re expecting is a lowercase alphanumeric value.


See also: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/checkbox

If the value attribute was omitted, the submitted data would be given a default value of on, so the submitted data in that case would be subscribe=on.

Leave a Comment