I have a field called field_server_type that contains the following static items in a select list: AIX, Linux, Windows, Other. I then have another field called field_server_operator. I want to dynamically populate the field_server_operator dynamically based on what the user select in the field_server_type. So if the user selects AIX from the select list in field_server_type, the allowed options would be "Brian" and "Bill" in the field_server_operator. If the user selects other from the field_server_type then it would populate the field_server_operator dynamically with the "Rob".
My guess is that I am using the wrong api call to try and get the information dynamically from the user. I don't think $form_state does what I think it does.
I am sure that there is some fairly easy way to do this. I am a noob when it comes to drupal. Any help you be appreciated. I have included some code I have come up with that does not work but it may better illustrate what I am trying to do. Thank you in advance for any help that you can give.
--Brian
$infra = array("Brian", "Bill");
$net = array("Rob");
$test = (string) $form_state['values']['field_server_type'] ;
if ($test == "AIX"){
return $infra;
}else{
return $net;
}
Comments
Comment #1
videographics commentedI agree. I would expect there should be some easy way to create dynamic select lists but I can't figure it out either. (I didn't even get as far as bnice5000's code.) I see it done from time to time on drupal installations but I'm not sure where to start. I would expect is has something to do with AJAX or AHAH and maybe using some PHP in the select list options but I've done my searches and only come up with this one issue asking for pretty much the same thing. Can anyone point us in the right direction?
Comment #2
markus_petrux commentedNot really easy. Take a look at: http://drupal.org/project/hierarchical_select
- #342992: Port HS support for Content Taxonomy to Drupal 6
- #257922: Hierarchical Select for Node Reference fields