Next Commerce
Checkout

The Form

The checkout form is driven by a single enhancer activated by data-next-checkout on a <form>. It finds your fields, validates them, populates the country and state dropdowns, manages a separate billing address, and submits the order.


How Fields Are Found

The SDK does not rely on input name or id. It locates each field by attribute:

  • data-next-checkout-field="<name>" — current convention
  • os-checkout-field="<name>" — legacy convention (still supported)

Both work; prefer data-next-checkout-field in new pages. The value is the standard field name, which the SDK maps to the order API for you.

Standard field names

Field namePurposeElement
emailEmail addressinput[type=email]
fnameFirst nameinput
lnameLast nameinput
phonePhone numberinput[type=tel]
address1Street addressinput
address2Apartment / suite (optional)input
cityCityinput
provinceState / provinceselect
postalPostal / ZIP codeinput
countryCountryselect

Card field names are covered in Payment.

address2 is the only address field that is always optional. province is required only for countries whose configuration marks a state as required.


Validation

Validation runs on submit and on field blur. If a field is invalid, the SDK marks it and shows a message; on submit it focuses and scrolls to the first error.

FieldRule
emailValid email format
fname, lnameLetters, spaces, hyphens, and apostrophes
phoneInternational format via intl-tel-input; falls back to a minimum digit count
cityLetters only, minimum 2 characters
postalCountry-specific format (e.g. US ZIP 12345 or 12345-6789)
provinceRequired when the selected country requires a state
countryMust be one of the campaign's available shipping countries

When a field fails, the SDK adds the has-error / next-error-field classes to it and writes the message into an error container (see Error display). A valid field gets no-error.

HTML5 native validation is bypassed — the form uses the SDK's validator instead, so the browser's built-in "Please fill out this field" bubbles will not appear.

Error display

The SDK writes each field's error message into a container it finds near the field. You can provide one explicitly:

<input data-next-checkout-field="email" type="email" />
<div data-next-error="email"></div>

os-checkout-error="email" is also accepted. If no container is found, the SDK creates an inline error label next to the field.


Country & State

The country dropdown is filled from the campaign's available shipping countries. The province dropdown is populated from the selected country's states. Changing the country:

  • Refreshes the province options for that country
  • Re-labels the state field (e.g. "State", "Province", "Region")
  • Re-labels and re-validates the postal field (e.g. "ZIP", "Postcode")

You can leave both <select> elements empty in your HTML — the SDK fills them.


Progressive Address Fields

To keep the form visually short, the city / state / postal block can stay hidden until the visitor starts a street address. Wrap those fields in a location container:

<div data-next-component="location">
  <input  data-next-checkout-field="city" />
  <select data-next-checkout-field="province"></select>
  <input  data-next-checkout-field="postal" />
</div>

The container is hidden (next-location-hidden) until address1 receives a value, then revealed. The matching billing container is data-next-component="billing-location".


Separate Billing Address

By default the billing address equals the shipping address. To let customers enter a different one, add a billing toggle and a billing form container:

<!-- toggle: checked = same as shipping -->
<input type="checkbox" name="use_shipping_address" checked />

<!-- shown only when billing differs from shipping -->
<div data-next-component="billing-form">
  <input data-next-checkout-field="billing-fname" />
  <input data-next-checkout-field="billing-lname" />
  <input data-next-checkout-field="billing-address1" />
  <input data-next-checkout-field="billing-city" />
  <select data-next-checkout-field="billing-province"></select>
  <input data-next-checkout-field="billing-postal" />
  <select data-next-checkout-field="billing-country"></select>
</div>

Billing fields use the same standard names prefixed with billing-. When the toggle says billing is the same as shipping, the billing form is hidden and only shipping is validated. When it differs, the billing form expands and its fields are validated too.

The container can also be marked with data-next-component="different-billing-address" (or the legacy os-checkout-element="different-billing-address") to control its visibility.


Component Containers

These optional containers let the SDK manage sections of the form. Each accepts the data-next-component form (preferred) or the legacy os-checkout-component / os-checkout-element form.

ContainerPurpose
data-next-component="shipping-form"Shipping fields wrapper
data-next-component="billing-form"Billing fields wrapper (animated open/close)
data-next-component="different-billing-address"Wrapper that toggles billing visibility
data-next-component="location"City / state / postal, revealed after address1
data-next-component="billing-location"Billing city / state / postal
data-next-component="shipping-field-row"A single field row

Next Steps

On this page