I made radio buttons with the forms api using this code:

"sex" => array(
    '#type' => 'radios',
        '#title' => t('Sex'),
        '#options' => array(t('M'), t('F')),

It works perfectly, but instead of storing an M or an F in the database, it stores a 0 or a 1. How can I decide what value is stored for each option?

1 Answer 1


The keys of the array set as #options determine the values and the values determine the labels.

In other words: The example in my question uses a regular array array(t('M'), t('F')) which, behind the scenes, is an associative array using non-negative integers as keys (same as array(0=>t('M'), 1=>t('F')). Since the radio buttons use these keys to know what to store in the database, the solution is simply to change them: array('M'=>t('M'), 'F'=>t('F')).

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.