<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
</head>
<body bgcolor="#ffffff" text="#000000">
<font size="-1"><font face="Arial">Well, I figured out the answer to my
question by looking in the code for the _form_validate() function in
form.inc. For those interested in the resolution, I hadn't unset the
$form['nice_menus_number']['#options'] setting in the form, so it was
still using the items in the select list as validation parameters.
Once I added this line<br>
<br>
unset($form[</font></font><font size="-1"><font face="Arial">$form['nice_menus_number']['#options'])<br>
<br>
to my form alter function, it worked just as I wanted.<br>
<br>
Steve<br>
</font></font><br>
-------- Original Message --------
<table class="moz-email-headers-table" border="0" cellpadding="0"
cellspacing="0">
<tbody>
<tr>
<th align="right" nowrap="nowrap" valign="baseline">Subject: </th>
<td>"Illegal Choice" Error When Changing Select List to Text Field</td>
</tr>
<tr>
<th align="right" nowrap="nowrap" valign="baseline">Date: </th>
<td>Wed, 16 Apr 2008 13:42:37 -0700</td>
</tr>
<tr>
<th align="right" nowrap="nowrap" valign="baseline">From: </th>
<td>Steve Edwards <a class="moz-txt-link-rfc2396E" href="mailto:killshot91@comcast.net"><killshot91@comcast.net></a></td>
</tr>
<tr>
<th align="right" nowrap="nowrap" valign="baseline">To: </th>
<td><a class="moz-txt-link-abbreviated" href="mailto:support@drupal.org">support@drupal.org</a></td>
</tr>
</tbody>
</table>
<br>
<br>
<font size="-1"><font face="Arial">I'm using the Nice Menus module, and
I would like to be able to have more than the 10 menus allowed by the
module. This limit is set by a hardcoded select list on the admin
settings page for the module. I want to modify the form by changing
the select list to a text field so that an arbitrary number of menus
can be selected. To do this, I'm using hook_form_alter() to modify the
nice_menus_number field in the nice_menus_admin_settings form. First
here is the form code in the module<br>
<br>
/**<br>
* Settings form as implemented by hook_menu<br>
*/<br>
function nice_menus_admin_settings() {<br>
$form['nice_menus_number'] = array(<br>
'#type' => 'select',<br>
'#title' => t('Number of Nice Menus'),<br>
'#description' => t('The total number of independent nice menus
(blocks) you want.'),<br>
'#default_value' => variable_get('nice_menus_number', '2'),<br>
'#options' => drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8,
9, 10)),<br>
);<br>
<br>
return system_settings_form($form);<br>
}<br>
<br>
and here is my form alter function:<br>
<br>
function cwl_form_alter($form_id, &$form) {<br>
switch ($form_id) {<br>
case 'nice_menus_admin_settings':<br>
$form['nice_menus_number']['#type'] = 'textfield';<br>
$form['nice_menus_number']['#size'] = 2; <br>
break;<br>
}<br>
}<br>
<br>
</font></font><br>
<font size="-1"><font face="Arial">This works in that it changes the
field type to a text field, and the value attribute is the value in the
nice_menus_number variable. This works fine as long as I select a
value of 10 or less. However, if I select a value higher than 10, I
get an error that says "</font></font>
<font face="Arial">An illegal choice has been detected. Please contact
the site administrator</font>."<br>
<br>
But, if I change my function to also use a select list, like this:<br>
<br>
function cwl_form_alter($form_id, &$form) {<br>
switch ($form_id) {<br>
case 'nice_menus_admin_settings':<br>
$form['nice_menus_number']['#options'] =
drupal_map_assoc(array(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13,
14, 15));<br>
break;<br>
}<br>
}<br>
<br>
<font face="Arial">it works fine, and I can select a value higher than
10. Since it's using the default system_settings_form() function,
there isn't a maximum value set somewhere. Plus, the default value is
being set correctly when the form is initially displayed. Can anybody
explain why a select list works, but a text field doesn't?<br>
<br>
Thanks.<br>
<br>
Steve</font><br>
<br>
</body>
</html>