Forum

Thread tagged as: Question, Forms

Checkbox question

How do I make a checkbox required? Add the required attribute doesn't seem to work.

~~~ <perch:input type="checkbox" id="accept" value="accept" required>

Chris Pritchard

Chris Pritchard 1 points

  • 3 years ago
Simon Clay

Simon Clay 127 points

Hi Chris,

I have just tested using your code above and it works. When trying to submit the form without ticking the box I see the 'Select this checkbox' message.

If your form is in a 'Content' region, make sure you've re-saved the region in Perch Admin.

Hi Simon, Thanks for the reply. I think that the message you are seeing is the browser validation, not Perch validation. If someone is using an older browser the form submits without any error being displayed.

I have the following error message under the checkbox, but it is never displayed. ~~~ <perch:error for="accept" type="required"><span class="help-block">The terms of this form must be accepted</span></perch:error>

BTW I am using Perch 3.0.13

Simon Clay

Simon Clay 127 points

Hi, I have added define('PERCH_HTML5', false); to perch/config.php to force the browser to use Perch validation and now see the perch error detection as expected when I try to submit without ticking the box. I think it's working.

You may want to update to the latest version and post your diagnostics.

Hi Simon, Hurrah! Upgrading to Perch 3.1.1 fixed it. Thanks for the help.

Simon Clay

Simon Clay 127 points

Ah! Good stuff.