2

I have a form where I am using radio buttons and when I use integers as the index, the form is saving and passing the value just fine. However if I use a string as the index it is saving nothing in the $form_state['storage']['values'].

Example - This works as expected:

$testArray = array(0 => 'test1', 1 => 'test2', 2 => 'test3');

$form['step0']['testthis'] = array (
    '#type' => 'radios',
    '#options' => $testArray
);

After submitting this example the $form_state will look like (with array index 2 selected):

- Form Storage -
Array
(
    [values] => Array
        (
            [step0] => Array
                (
                    [testthis] => 2
                )

        )

)

Example - This does not work as expected... for me!

$testArray = array('test01' => 'test1', 'test02' => 'test2', 'test03' => 'test3');

$form['step0']['testthis'] = array (
    '#type' => 'radios',
    '#options' => $testArray
);

After submitting this example the $form_state will look like (with array index test03 selected):

- Form Storage -
Array
(
    [values] => Array
        (
            [step0] => Array
                (
                    [testthis] =>
                )

        )

)

I expect it to output

- Form Storage -
Array
(
    [values] => Array
        (
            [step0] => Array
                (
                    [testthis] => test03
                )

        )

)

Any insight would be most appreciated!

Thank you.

Edit: I forgot to mention that the HTML element is output just fine. So using the string index the element looks like:

<input type="radio" id="edit-step0-testthis-test3" name="step0[testthis]" value="test03" class="form-radio">

1 Answer 1

1

My mistake!

I am using AJAX to submit the form and selecting the radio button using the .attr() function.

I was using an improper name in the element selector thus nothing was technically being selected.

Hope that helps someone else!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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