I am fairly new to php, and have done multiple searches to try and fix my problem and I either not searching on the right thing or I am not finding the answer I need. I have a form with a select list that is generated from a function that gets a list of roles from the drupal roles table (just the name), but it excludes the two roles that are set up by default (anonymous user and authenticated user) as well as any role that looks like it has been added for the purpose of moderating or administration. I realize that a select list values are stored as numeric values that increment for each item starting at 0 and going until last item has a number. What I am having trouble with is when you call $form_state['values']['form_item'] the value will be whatever number item is selected, but how do you get the text value that corresponds to that number? I need this because if there are no roles returned from the function I set a value and I need to construct a if statement to check if $form_state['values']['form_item'] = 0 && ?? name = something.
Unfortunately I do not know how to return the text value of the select list. I have tried with $form['form_item']['#value'] and $elements['#value'] and either I doing it wrong or have an error for it doesn't seem to work.
Comments
I am assuming you are doing
I am assuming you are doing this in either a submit or validate function... if you have devel enabled (which i recommend you do), add dsm($form) in the function -- the options are listed there and you can pull the text from it, not at a computer i can confirm this on but I think it is $form[#options] or #values like you mentioned, something like that depending on how your form is configured.
Toronto Website Developer
Yes I was using it in a
Yes I was using it in a validate function, sorry I should have stated that. I have the devel module set up in a block, but I was using it (dsm) with the variables I was creating which were returning empty. You were correct it was $form['#options'], but even with that it is only half working. What I mean is when you have no roles (other then the ones I am excluding) it works giving the error as I expect, but if you add roles it gives the error
Fatal Error: Maximum function nesting level of '100' reached aborting in includes/form.inc 1433
I seem to be either to get it to work with no roles and then have to switch code to get it to work with roles, I can't seem to get it to work with both. I believe it is the freeradius_get_roles() function that is causing it.
freeradius.admin.inc.php
freeradius.module.php
I managed to fix it so it
I managed to fix it so it will display with out errors for both when there no roles set and when there is roles set. I did it by changing the form:
from this:
to this:
I also changed the freeradius_get_roles function from this:
to this:
I found this solution here http://drupal.org/node/730796. The problem is that with the following if statement in the validate function it works if there no roles as expected (gives the form_set_error) but when there are roles added and shouldn't be failing it does (by also giving the form_set_error).