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

Text fields with a required marker, an error and an input groupText fields with a required marker, an error and an input group

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>
ClassWhat it is
.ph-formA form: fields stacked 16px apart
.ph-form-rowPuts fields side by side on wide screens (each at least 200px)
.ph-fieldOne field: label, input, then hint or error
.ph-labelThe label (13px, semibold)
.ph-requiredThe red asterisk after a required field's label
.ph-inputText, email, number, date and search inputs
.ph-input-group / .ph-input-addonAn input with a prefix or suffix, or an icon inside it
.ph-hintHelp under the input (12px)
.ph-errorThe error under the input, in red

An input with aria-invalid="true" gets a red border.

Selects and text areas

A select and a text areaA select and a text area

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

Checkboxes, radio buttons and switchesCheckboxes, 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>
ClassWhat it isUse for
.ph-checkA label wrapping a checkbox or radio button and its textEvery checkbox and radio button
.ph-switch (on a checkbox)A 32 × 18px switchSettings that take effect straight away
.ph-fieldsetAn unstyled fieldset with a 13px legendGrouping related choices
.ph-checkbox / .ph-radioA checkbox or radio button on its own, without a label wrapperTable 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

A sliderA slider

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

  1. Validate on submit (add novalidate to the form so the browser's own bubbles don't appear).
  2. For each invalid field, set aria-invalid="true", add a .ph-error under it, and point aria-describedby at the error.
  3. Move focus to the first invalid field.
  4. While saving, set aria-busy="true" on the submit button.
  5. 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

HTMLReact (ph-app-kit-react)
.ph-input, .ph-textareaStyledTextField
.ph-selectStyledSelect
.ph-check checkboxStyledCheckbox
.ph-switchToggleSwitch, or LabeledToggle with labels
.ph-sliderSettingSlider
.ph-field + .ph-labelFormField, 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.