Skip to main content

<primer-card-form>

Container for card payment inputs. Provides context to child components, handles validation, and manages form submission. Uses secure iframes for PCI compliance.

Quick Reference

Parent<primer-checkout>
Propertiesdisabled, hide-labels
Slotcard-form-content
Emitsprimer:card-success, primer:card-error
Listens forprimer:card-submit

Examples

Default Layout

Renders all card inputs automatically:
<primer-card-form></primer-card-form>
Renders: Card number, expiry, CVV, cardholder name, and submit button.

Disabled State

<primer-card-form disabled></primer-card-form>

Hidden Labels

<primer-card-form hide-labels></primer-card-form>

Custom Layout

<primer-card-form>
  <div slot="card-form-content">
    <primer-input-card-number></primer-input-card-number>
    <div style="display: flex; gap: 8px;">
      <primer-input-card-expiry></primer-input-card-expiry>
      <primer-input-cvv></primer-input-cvv>
    </div>
    <primer-input-card-holder-name></primer-input-card-holder-name>
    <button type="submit">Pay Now</button>
  </div>
</primer-card-form>

With Error Container

<primer-card-form>
  <div slot="card-form-content">
    <primer-input-card-number></primer-input-card-number>
    <primer-input-card-expiry></primer-input-card-expiry>
    <primer-input-cvv></primer-input-cvv>
    <primer-error-message-container></primer-error-message-container>
    <primer-card-form-submit></primer-card-form-submit>
  </div>
</primer-card-form>

Properties

PropertyAttributeTypeDefaultDescription
disableddisabledbooleanfalsePrevents form submission
hideLabelshide-labelsbooleanfalseHides labels on all inputs

Events

Emitted Events

EventDescriptionPayload
primer:card-successForm submitted successfully{ result: unknown }
primer:card-errorValidation errors occurred{ errors: ValidationError[] }

Listened Events

EventDescription
primer:card-submitTriggers form submission
External submit example:
document.getElementById('my-button').addEventListener('click', () => {
  document.dispatchEvent(
    new CustomEvent('primer:card-submit', {
      bubbles: true,
      composed: true
    })
  );
});
Note: bubbles: true and composed: true are required for shadow DOM traversal.

Slots

SlotDescription
card-form-contentCustom layout for card inputs. Replaces default when provided.

Methods

MethodDescription
submit()Programmatically submit the form
const cardForm = document.querySelector('primer-card-form');
await cardForm.submit();

CSS Properties

PropertyDescriptionDefault
--primer-space-smallGap between inline elements8px
--primer-space-mediumGap between block elements16px

Dependencies

Internally uses:
ComponentPurpose
primer-input-card-numberCard number input
primer-input-card-expiryExpiry date input
primer-input-cvvCVV input
primer-input-card-holder-nameCardholder name input
primer-card-form-submitSubmit button

Cardholder Name Configuration

checkout.options = {
  card: {
    cardholderName: {
      visible: true,       // Show field (default: true)
      required: true,      // Make required (default: true)
      defaultValue: ''     // Pre-fill value
    }
  }
};

Co-branded Card Schemes

Supports co-branded cards like Cartes Bancaires (CB). Network switcher displays automatically when detected. No configuration needed.

Submit Options

MethodExample
<primer-card-form-submit>Built-in, localized
<button type="submit">Standard HTML
<primer-button type="submit">Primer button
data-submit attributeAny element
primer:card-submit eventProgrammatic

Validation

  1. Validates all inputs on submission
  2. If invalid, dispatches primer:card-error
  3. Child inputs display error messages
  4. If valid, proceeds with payment

States

StateDescriptionVisual Change
ReadyForm ready for inputAll inputs enabled
ValidatingValidation in progressInputs may show loading
ValidAll inputs pass validationSubmit button enabled
InvalidOne or more validation errorsError states on inputs
SubmittingPayment being processedInputs disabled, button loading
Disableddisabled attribute setAll inputs disabled, muted appearance

Usage Guidelines

Do

  • Place all card inputs inside <primer-card-form>
  • Include <primer-error-message-container> for payment failures
  • Use primer:card-submit event for external submit buttons
  • Configure cardholder name via SDK options

Don’t

  • Don’t use alongside <primer-payment-method type="PAYMENT_CARD"> (causes duplicates)
  • Don’t place card inputs outside the form
  • Don’t use multiple card forms on one page
Using both <primer-card-form> and <primer-payment-method type="PAYMENT_CARD"> in the same layout creates duplicate card forms. Choose one approach.

Content Guidelines

Submit button text

DoDon’t
”Pay now""Submit"
"Complete payment""Pay"
"Pay $49.99""OK”

Error messages

DoDon’t
”Card number is invalid""Error"
"Card has expired""Invalid input”