[development] Forms API question: "checkboxes" type and
Peter Wolanin
pwolanin at gmail.com
Thu Sep 28 22:03:18 UTC 2006
Dear Scott,
if I'm understanding your question correctly, you're trying to get a
set of checkboxes in an impementation of hook_settings to return an
array containing only the selected elements?
If so, I wasted a couple hours on this same dilema and finally found
the solution:
include the array_filter element within your form:
$form['array_filter'] = array('#type' => 'value', '#value' => TRUE);
I also updated the hook_settings developer docs for 4.7 to reflect
this, though perhaps it should be more verbose or explicit (I'm not
paying close enough attention to FAPI to know if this is still true
for 5.0):
http://api.drupal.org/api/4.7/function/hook_settings
Date: Thu, 28 Sep 2006 14:21:43 -0400
From: Syscrusher <syscrusher at 4th.com>
Subject: [development] Forms API question: "checkboxes" type and
validation thereof
Message-ID: <200609281421.43884.syscrusher at 4th.com>
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.
More information about the development
mailing list