[development] Forms API question: "checkboxes" type and validation thereof

Richard Morse remorse at partners.org
Thu Sep 28 20:11:14 UTC 2006

Hi!  In the conversion to 5.0, they're getting rid of hook_settings.   
However, there is no reason that you can't make the conversion in 4.7  
modules.  Just add a MENU_NORMAL_ITEM at the path 'admin/settings/ 
yourmodule', and implement your own form handling.

If you want an example of a place I do this, I can send you a module  
I've written that handles this kind of issue off list.

(Also, you will want to know about array_filter()).


On Sep 28, 2006, at 2:21 PM, Syscrusher wrote:

> 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