By stretchwickster on
Hi there,
I'm trying to add a checkbox just before the "Create new account" button on the user registration page.
I looked up the argument list in the drupal api and am led to believe that by submitting "TRUE" for the last argument, I am indicating that it should be a mandatory field i.e. it must be ticked for the form submission to be valid. I see the checkbox as expected but no red asterisk appears next to it and the form submits without it being checked. Am I missing something here???
Below is the code I have inserted into the user.module file.
$output .= form_checkbox('I have read and agree to the site\'s <a href="termsofuse" target="_blank">terms of use</a> and <a href="privacypolicy" target="_blank">privacy policy</a>', 'agreetoterms', 1, FALSE, NULL, NULL, TRUE);
Your assistance would be much appreciated!
Comments
The concept
The concept of a 'required checkbox' is a bit of an oxymoron.
Although lotsa folk have started using it like you have to signal terms & conditions (yawn) technically the purpose of a checkbox being on a page is to be selected or not.
'required' means 'required to have a value'
The checkbox always HAS a value - true or false.
:)
What you are wanting is content validation - that the value of the checkbox is equal to a certain value - true.
This is the same level of logic as requiring that the name field is all lower-case, or that the selected country is US. You gotta do it in code.
Do you follow the concept here?
So, instead try a single radio box. Logically, through the UI and code, a radio CAN be required to be selected, because it starts in an undefined state, but choosing a button sets it to something. Not choosing anything from the radiogroup leaves it undefined - an illegal position.
Just an idea.
Or have them type 'yes' in a box. or choose a select.
Or just bloody well don't bother. The whole concept is flawed, annoying, untrue and has no legal weight.
.dan.
How to troubleshoot Drupal | http://www.coders.co.nz/
.dan. is the New Zealand Drupal Developer working on Government Web Standards
Thanks for the comments Dan
Thanks for the comments Dan - your view is much appreciated.
After posting I realised that no checkboxes have a red asterisk next to them anyway, for the very reason you pointed out. I was just being a bit lazy and hoping that I could validate it by setting $required to true!
I may well try the radio button option - thanks for suggesting that!
Use the Legal module
I just stumbled across the 'Legal' module (when reading another post about implementing a terms & conditions checkbox at the end of the registration page). It has a simple installation procedure and does exactly what I wanted to do - block access to those users who don't tick the T&Cs checkbox.