Forms
On this page
Kit forms put the label above each input, a hint under it, and an error under the field when the value is wrong. Native inputs get the kit's look, so there's nothing to set up beyond the classes.
Text fields


Figure 1: Two fields side by side (one showing an error) and an input with a prefix and suffix
<form class="ph-form" novalidate>
<div class="ph-form-row">
<div class="ph-field">
<label class="ph-label" for="name">Venue name <span class="ph-required">*</span></label>
<input class="ph-input" id="name" name="name" required />
</div>
<div class="ph-field">
<label class="ph-label" for="email">Contact email</label>
<input class="ph-input" id="email" name="email" type="email"
aria-invalid="true" aria-describedby="email-error" />
<p class="ph-error" id="email-error">Enter a full email address.</p>
</div>
</div>
<div class="ph-field">
<label class="ph-label" for="fee">Joining fee</label>
<div class="ph-input-group">
<span class="ph-input-addon">$</span>
<input class="ph-input ph-num" id="fee" name="fee" inputmode="decimal" aria-describedby="fee-hint" />
<span class="ph-input-addon">AUD</span>
</div>
<p class="ph-hint" id="fee-hint">Charged once, on sign-up.</p>
</div>
</form>
| Class | What it is |
|---|---|
.ph-form | A form: fields stacked 16px apart |
.ph-form-row | Puts fields side by side on wide screens (each at least 200px) |
.ph-field | One field: label, input, then hint or error |
.ph-label | The label (13px, semibold) |
.ph-required | The red asterisk after a required field's label |
.ph-input | Text, email, number, date and search inputs |
.ph-input-group / .ph-input-addon | An input with a prefix or suffix, or an icon inside it |
.ph-hint | Help under the input (12px) |
.ph-error | The error under the input, in red |
An input with aria-invalid="true" gets a red border.
Selects and text areas


Figure 2: A select and a text area with a hint
<select class="ph-select" id="tz" name="tz">
<option>Australia/Brisbane</option>
<option>Australia/Sydney</option>
</select>
<textarea class="ph-textarea" id="notes" name="notes" rows="3"></textarea>
For formatted text (bold, lists, links), use the rich text editor.
Checkboxes, radio buttons and switches


Figure 3: Checkboxes, radio buttons and switches grouped in fieldsets
<fieldset class="ph-fieldset">
<legend>Bookings</legend>
<label class="ph-check"><input type="checkbox" name="holidays" /> Open on public holidays</label>
<label class="ph-check"><input type="radio" name="seating" value="indoor" /> Indoor only</label>
<label class="ph-check"><input type="checkbox" class="ph-switch" role="switch" name="late-booking" /> Late booking alerts</label>
</fieldset>
| Class | What it is | Use for |
|---|---|---|
.ph-check | A label wrapping a checkbox or radio button and its text | Every checkbox and radio button |
.ph-switch (on a checkbox) | A 32 × 18px switch | Settings that take effect straight away |
.ph-fieldset | An unstyled fieldset with a 13px legend | Grouping related choices |
.ph-checkbox / .ph-radio | A checkbox or radio button on its own, without a label wrapper | Table row selection |
Use a checkbox when the choice is saved with the form, and a switch when it applies straight away.
Give switches role="switch".
Sliders


Figure 4: A slider showing its value in the label
<div class="ph-field">
<label class="ph-label" for="capacity">Capacity limit: <span id="capacity-value" class="ph-num">120</span></label>
<input class="ph-slider" type="range" id="capacity" name="capacity" min="20" max="400" step="10" value="120" />
</div>
Show the current value next to the label and update it on input.
Validation and saving
- Validate on submit (add
novalidateto the form so the browser's own bubbles don't appear). - For each invalid field, set
aria-invalid="true", add a.ph-errorunder it, and pointaria-describedbyat the error. - Move focus to the first invalid field.
- While saving, set
aria-busy="true"on the submit button. - When it's saved, show a toast:
phApp.toast('Venue settings saved').
The server checks every value again. When it rejects one, it returns {"error": "what to fix"}
with a 4xx status, and the form shows that message next to the field or in a callout.
React
| HTML | React (ph-app-kit-react) |
|---|---|
.ph-input, .ph-textarea | StyledTextField |
.ph-select | StyledSelect |
.ph-check checkbox | StyledCheckbox |
.ph-switch | ToggleSwitch, or LabeledToggle with labels |
.ph-slider | SettingSlider |
.ph-field + .ph-label | FormField, FieldLabel |
Date and time inputs: DateSelect, TimeSelect, DateRangeSelect, MonthRangeSelect and
TimezonePicker. See React.
Guidelines
- Every input has a visible label. Placeholders are examples, not labels.
- Write hints and errors that say what to do: "Enter a full email address", not "Invalid input".
- Ask only for what you need, and set sensible defaults.
- Save buttons say what they save: "Save venue settings".
- Settings forms use a narrow page (
.ph-page--narrow). See Page patterns.
Related
- Segmented control
- Dialogs and drawers: forms in a dialog
- Toasts