1

I am creating a radio button like this:

$form['paymentMethodSelect'] = array(
    '#type' => 'radio',
    '#title' => $this->t('How would you like to make payment?'),
);

This works and creates a single radio button. Now according to documentation, to create multiple radio buttons, you change "radio" to "radios". But if I do that:

$form['paymentMethodSelect'] = array(
    '#type' => 'radios',
    '#title' => $this->t('How would you like to make payment?'),
    '#default_value' => 'eft',
    '#options' => [
        'eft' => 'EFT (Electronic Funds Transfer)',
        'cc' => 'Credit Card',
    ],
);

But if I do that then I end up with this:

enter image description here

Any idea why I am not seeing two radio buttons as expected?

1

Your code still shows radio instead of radios for '#type' attribute.

$form['paymentMethodSelect'] = array(
    '#type' => 'radios',
    '#title' => $this->t('How would you like to make payment?'),
    '#default_value' => 'eft',
    '#options' => [
        'eft' => 'EFT (Electronic Funds Transfer)',
        'cc' => 'Credit Card',
    ],
);

Otherwise there is no other problem I see in your code.
Sample code from D.O

$form['settings']['active'] = array(
  '#type' => 'radios',
  '#title' => $this->t('Poll status'),
  '#default_value' => 1,
  '#options' => array(0 => $this->t('Closed'), 1 => $this->t('Active')),
);
  • 1
    Sorry, that was a mistake on my side. But with "radios" I still get the error. Even if I use the exact sample you provided, I also see what is showin in the screenshot. It's like it doesnt understand what "radios" is, and then defaults to what you see there. – coderama Oct 25 '16 at 11:32

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.