Community Documentation

HOW TO: Remove "N/A" from list of radio button choices

Last updated October 29, 2009. Created by webchick on October 29, 2009.
Log in to edit this page.

In CCK version 6, non-required radio button fields add an extra "N/A" option. This is a deliberate decision made by the CCK module maintainers -- see http://drupal.org/node/368771 for discussion -- but sometimes this is not what you want. Here's a helpful snippet that can be adapted to remove this extra option on CCK radio button fields for your site.

<?php
/**
* Implementation of hook_elements().
*
* This extends optionwidgets_elements() to add in additional processing.
* Note that your module must be weighted higher than optionwidgets
* for this code to take effect.
*/
function example_elements() {
 
$type['optionwidgets_buttons']['#process'][] = 'remove_radio_na';
  return
$type;
}

/**
* Unset the N/A option on option widget radio buttons.
*/
function remove_radio_na($element) {
  unset(
$element['value']['#options']['']);
  return
$element;
}
?>

Page status

No known problems

Log in to edit this page

About this page

Drupal version
Drupal 6.x
Audience
Developers and coders

Structure Guide

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License.