HTML forms: selections
This course covers the HTML controls that let visitors choose values instead of typing them. It explains checkboxes, checkbox groups, radio buttons and select menus, plus optgroup, multiple and datalist. Each lesson shows what the browser submits, including the silence of unchecked boxes, and how Rails parses the result into params. It also covers pre-selected states with checked and selected, placeholder options, and the hidden input trick. A final preferences form combines every control, and the course stresses that server validations still judge all input.
What you'll learn
- ✓How to pick a selection control by how many options exist and how many may be chosen
- ✓Why unchecked checkboxes submit nothing and how Rails pairs them with a hidden input
- ✓How the [] name suffix turns repeated keys into arrays in Rails params
- ✓How radio groups share a name and why a default should be pre-checked
- ✓How select options separate the visible label from the submitted value
- ✓When to use optgroup, multiple and datalist, and why server validation still matters
Choosing, not typing
The previous course gave your forms text boxes, and text boxes have a weakness you will fight for your whole career: people type anything into them. Ask for a country and you'll receive "Brazil", "brasil", "BR", "Brasil 🇧🇷", and "brazl". Ask "do you accept the terms?" and a text box invites an…
Read the full lesson free →Curriculum
7 lessonsChoosing, not typing
Explains why selection controls beat free text and how checkboxes, radios and selects match different cardinalities.
Checkbox: the On/Off switch
Covers single checkboxes, the default value on, unchecked silence, the Rails hidden input pair and checked.
Checkbox groups: many from many
Shows how checkboxes sharing a name submit repeated keys and how the [] suffix builds arrays in Rails.
Radio buttons: one of a few
Explains browser-enforced radio groups by shared name, single-value submission and why a default should be pre-checked.
select and option: the dropdown
Covers select and option, the split between label and value, the selected attribute and placeholder options.
Grouped, multiple, and suggested
Adds optgroup headings, multi-selection with multiple and size, and datalist suggestions that do not restrict input.
Putting it together: a preferences page
Builds a preferences form with every control and traces its submission into the shape of Rails params.