0

In a form I'm trying to take a value a user selected from a radio button and compare it with what's in the database. The value for the radio button is stored in $form_state['storage']['level'].

The list field in my resource type for this set of items is set as follows:

Novice|Novice Experienced|Experienced Professional|Professional

And yet, when I echo out the value in $form_state['storage']['level'] it just gives me what appears to be the delta and not the value of the field. Would someone please enlighten me as to how the value is obtained in php code?

4
  • 2
    Where is your code? Validate function, submit function or somewhere else?
    – rooby
    Jan 21, 2015 at 21:48
  • Hi. I've tried it in the submit handler as well as the function the submit handler sends the user to AFTER submitting the form. Here's the code I'm using to echo: echo $form_state['storage']['level'];
    – Sage
    Jan 21, 2015 at 22:20
  • 1
    dsm the $form_state var. Usually the values exist in $form_state['values']...
    – sareed
    Jan 21, 2015 at 22:31
  • One line of code is not enough. Also what is the expected result and actual result. Jan 21, 2015 at 22:34

2 Answers 2

1

Try using $form_state['values'] instead of $form_state['storage'].

Check out the $form_state keys for a bit more information.

2
  • Thanks. I tried dsm()ing the values and just get 0, 1, and 2. Moreover, when I use $form_state['values'] I just get 'array' when I echo it out. Maybe it's the way I'm storing the information to begin with? Ugh this comment box is so limited. Ummm...so when I setup the radio boxes that users select from I use the following: '#options' => array( t('Grant writing'), t('Grants Research'), t('Grants Management'), t('Strategic Planning')) ); That apparently gets read by the system as 0, 1, 2, or 3 anad not the options themselves. Is there a way to get the actual values?
    – Sage
    Jan 22, 2015 at 3:12
  • $form_state['values'] is an array so you can't echo it. Use dpm() or similar.
    – rooby
    Jan 22, 2015 at 5:20
0

If you try to compare a field value to hide or alter other filds field dependecies module might help you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.