Skip to content

Instantly share code, notes, and snippets.

@opi
Created August 3, 2018 20:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save opi/da3c96f2401949d7d7103d50dd1c363d to your computer and use it in GitHub Desktop.
Save opi/da3c96f2401949d7d7103d50dd1c363d to your computer and use it in GitHub Desktop.
<?php
$form['numeric_default_zero'] = array(
'#type' => 'radios',
'#title' => "Only numeric keys, starting at 0. #default_value to 0",
'#default_value' => 0,
'#options' => array(
0 => "key: 0",
1 => "key: 1",
2 => "key: 2",
),
'#description' => "GOOD: radio 0 is selected",
);
$form['numeric_default_false'] = array(
'#type' => 'radios',
'#title' => "Only numeric keys, starting at 0. #default_value to FALSE",
'#default_value' => FALSE,
'#options' => array(
0 => "key: 0",
1 => "key: 1",
2 => "key: 2",
),
'#description' => "GOOD: no radio selected",
);
$form['mixed_default_zero'] = array(
'#type' => 'radios',
'#title' => "Mixed numeric & alpha keys, starting at 0. #default_value to 0",
'#default_value' => 0,
'#options' => array(
0 => "key: 0",
1 => "key: 1",
'a' => "key: a",
'b' => "key: b",
),
'#description' => "<strong>BAD</strong>: 0 and alpha radios have 'checked' attribute, last one appear as selected",
);
$form['mixed_default_false'] = array(
'#type' => 'radios',
'#title' => "Mixed numeric & alpha keys, starting at 0. #default_value to FALSE",
'#default_value' => FALSE,
'#options' => array(
0 => "key: 0",
1 => "key: 1",
'a' => "key: a",
'b' => "key: b",
),
'#description' => "GOOD: no radio selected",
);
$form['alpha_default_zero'] = array(
'#type' => 'radios',
'#title' => "Only alpha keys. #default_value to 0",
'#default_value' => 0,
'#options' => array(
'a' => "key: a",
'b' => "key: b",
),
'#description' => "<strong>BAD</strong>: every radios have 'checked' attribute, last one appear as selected",
);
$form['alpha_default_false'] = array(
'#type' => 'radios',
'#title' => "Only alpha keys. #default_value to FALSE",
'#default_value' => FALSE,
'#options' => array(
'a' => "key: a",
'b' => "key: b",
),
'#description' => "GOOD: no radio selected",
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment