[development] Forms API question: "checkboxes" type and validation
thereof
Syscrusher
syscrusher at 4th.com
Thu Sep 28 18:21:43 UTC 2006
Greetings!
This may be a dumb question, but I can't seem to find any Drupal core example
code that does what I need.
In a module settings form, I have a "checkboxes" form element with a list of
options of the format:
array($short_name => $description, ...)
The goal (which is being achieved at the HTML level) is to have code like this:
<label class="option"><input type="checkbox" name="..." value="$short_name"/>
$description</label>
That's all working fine, and the returned values for checked boxes are as
desired. I have no problem getting the FAPI to render and process the form
correctly, but what's happening is that any *unchecked* boxes are being set to
the value zero rather than being left unset. This is causing extra cruft in my
database records because what I really want is just the list of shortnames of
the checked values.
I've been through the docs and examples, and looked at several parts of Drupal
core, to see how to use #validate on a form, but is there a way to use it on
just one form element and then *change* the value of that element by removing
undesired parts? Or is that something I should do in #submit?
Several parts of the docs have "almost" what I need, I think:
http://drupal.org/node/51104
http://drupal.org/node/58689
One of the reasons this is so tricky is that the form element in question happens
to be used in the module settings (where I don't have control over the processing)
and also in the user preferences (where I also don't have control over the
processing). I need to be able to hook in somewhere between when the browser
sends via POST and when the module and user settings get stored.
What's the correct approach (in general terms, not looking for someone to write
the code for me) to do this?
Thanks for any suggestions.
Syscrusher
--
-------------------------------------------------------------------------------
Syscrusher (Scott Courtney) Drupal page: http://drupal.org/user/9184
syscrusher at 4th dot com Home page: http://4th.com/
More information about the development
mailing list