Skip to header Skip to main navigation Skip to main content Skip to footer
  • Log in
Home
DrupalVIP
Freelancer service with great care and enthusiasm.
  • Home
  • Products
  • Blog
  • Support
    • Dictionary
    • Drupal Resources
    • External Resources

How to use the Form Radios

Breadcrumb

  • Home
  • DrupalVIP Support
  • How to use the Form Radios
DrupalVIP Support

Custom form sometimes need to have radio buttons, in order to create small selection options.
 

setting radios in a custom form:

# the options to display in our form radio buttons
$options = array(
  'punt' => t('Punt'),
  'field_goal' => t('Kick field goal'), 
  'run' => t('Run'),
  'pass' => t('Pass'),
);

$form['status'] = array(
  '#type' => 'radios',
  '#title' => t('What to do on fourth down'),
  '#options' => $options,
  '#description' => t('What would you like to do on fourth down?'),
  '#default_value' => $options['punt'],
);

 

Element properties may be set on single option items as follows.

$form['settings']['active'][0]['#description'] = $this->t('Description for the Closed option.');

 

On the submit callback method, here is how you get the radios selection:

$status = $form_state->getValue('status'); 

The status from the submit will hold the key of the selected option.

 

Drupal Development

Drupal Development
Code Snippet
$form['settings']['active'] = [
    '#type' => 'radios',
    '#title' => $this->t('Poll status'),
    '#default_value' => 1,
    '#options' => [
        0 => $this->t('Closed'),
        1 => $this->t('Active'),
    ],
]
Read More
class Radios
Tags
Drupal 9
Drupal Support
Drupal 10
Radios
Custom Form
Form API
Form
Form Element

The Freelancer Assistance

Fullstack Service

Fullstack Service

Proactive Maintenance

Proactive Maintenance

Site Management

Site Management

Drupal Development

Drupal Development

Drupal Training

drupal training session

Drupal Shared Space

Drupal Shared Space
Review All Services

Buy Hourly Support

 

Drupal platform support for complex websites. The service includes support, training, troubleshooting, fixes, updates, tool creation and module building.
* Minimum order is for 5 hours of support
* For every 20 hours of order you will be entitled to an additional hour of support
* For every 50 hours of order you will be entitled to 5 additional hours of support

 

>> Payment <<

 
cards

מופעל על-ידי paypal

Legal

  • Home
  • Contact
  • Products

Footer menu

  • Home
  • Contact
  • Products

Copyright © 2026 DrupalVIP project of Automatic Frameworks - All rights reserved

Developed and Maintain by Jonathan Ben Hur Freelancer