17 September 2009 at 6:24pm
What does "same name" mean? That they all have the same label in the form, or that they have the same name? If you're trying to do the latter, please explain why, because using the same name for different form-fields usually breaks the functionality of a form (only one value is returned).
Also: Do you really mean disabled, or unchecked?
17 September 2009 at 7:26pm
(Last edited: 17 September 2009 7:32pm),
Ok, I see. I guess that isn't supported with the CheckboxSetField, since it uses the name as key in an array structure. Therefore duplicate keys aren't possible (existing keys will be overwritten). Your best bet is to write some custom code that creates a bunch of CheckboxFields with the desired properties. You should also use count as name, instead of count. That will allow you to access the values as array on the server-side (in php). Read here for further information: http://www.bestcodingpractices.com/php_multiple_values_in_one_form_variable-30.html
Update The CheckboxSetField actually uses the "array" syntax mentioned above. Field names will be setname[fieldkey]. But there's no way to disable single elements. You could extend the CheckboxSetField class and add the required functionality though.
18 September 2009 at 6:21pm
I would probably create a new class, say AdvancedCheckboxSetField that extends CheckboxSetField. Then I would implement some methods that allow me to enable/disable a checkbox by index, eg. enableCheckbox($index) and disableCheckbox($index). The enabled status will simply be stored in an array. After that, all that's left to do is to override the Field method. There's pretty much code in the CheckboxSetField::Field method, but most of that can probably be copied over to the new class. Instead of using the global "disabled" flag, you can then check your "is-enabled-array" for each index individually and write html markup accordingly.
You can place your new class in mypage/code/forms and also reuse it for other projects..