Skip to content

SIRET field with validation in WordPress

A SIRET or SIREN field that checks the Luhn key as you type, handles the La Poste exception, formats the number and links to the official business directory.

Here is an excerpt of this component's code in WordPress. The full code is free for members, ready to copy into your project.

This component also comes in

Open in a new tab

The code in WordPress

champ-siret-verification.php
<?php
/**
 * Plugin Name: Forge, Champ SIRET avec vérification
 * Description: Un champ SIRET ou SIREN qui vérifie la clé de Luhn pendant la saisie, gère l’exception de La Poste, met le numéro en forme et renvoie vers l’Annuaire des entreprises. Ajoute la composition « Champ SIRET avec vérification » à l'éditeur de blocs.
 * Version: 1.0.0
 * Requires at least: 6.6
 * Requires PHP: 8.1
 * Author: Forge
 * License: GPL-2.0-or-later
 * License URI: https://www.gnu.org/licenses/gpl-2.0.html
 * Text Domain: forge-champ-siret-verification
 *
pattern.html
<!-- wp:html -->
<form class="fsi" data-fsi novalidate aria-labelledby="fsi-titre">
        <h2 class="fsi-title" id="fsi-titre">Votre entreprise</h2>
        <p class="fsi-intro">Le numéro figure sur vos factures et sur l’avis de situation au répertoire Sirene.</p>
        <div class="fsi-field">
          <label class="fsi-label" for="fsi-numero">Numéro SIRET ou SIREN</label>
          <input class="fsi-input" id="fsi-numero" name="numero" inputmode="numeric" autocomplete="off" spellcheck="false" placeholder="732 829 320 00074" aria-describedby="fsi-aide fsi-etat">
          <p class="fsi-help" id="fsi-aide">SIREN : 9 chiffres. SIRET : 14 chiffres (SIREN + numéro d’établissement). Espaces acceptés.</p>
          <p class="fsi-state" id="fsi-etat" data-fsi-state="vide" aria-live="polite"><span class="fsi-dot" aria-hidden="true"></span><span data-fsi-message>0 chiffre saisi.</span></p>
          <a class="fsi-link" data-fsi-link href="https://annuaire-entreprises.data.gouv.fr/" target="_blank" rel="noopener" hidden>Voir la fiche dans l’Annuaire des entreprises<span class="fsi-sr"> (nouvel onglet)</span></a>
        </div>
        <button class="fsi-submit" type="submit">Continuer</button>
script.js
(() => {
  if (!document.querySelector(".fsi")) return;
  document.querySelectorAll("[data-fsi]").forEach((root) => {
    const on = (el, type, fn) => el.addEventListener(type, fn);
    const input = root.querySelector('[name="numero"]');
    const state = root.querySelector("[data-fsi-state]");
    const message = root.querySelector("[data-fsi-message]");
    const link = root.querySelector("[data-fsi-link]");
    const status = root.querySelector("[data-fsi-status]");
    const luhn = (digits) =>
      [...digits].reverse().reduce((sum, char, i) => {
        const n = Number(char) * (i % 2 ? 2 : 1);
style.css
:root {
  --fsi-card: #ffffff;
  --fsi-text: #1a2230;
  --fsi-muted: #4b5567;
  --fsi-accent: #0b5cad;
  --fsi-line: #c8d0dc;
  --fsi-ok: #1d7a3e;
  --fsi-error: #b42318;
  --fsi-wait: #8a5a00;
  --demo-champ-siret-verification-bg: #e9edf2;
  --demo-champ-siret-verification-text: #1a2230;
}

Free component: copy it freely, including for commercial projects.

Forms and inputs components in WordPress
  • A quote request form for tradespeople: the customer describes the work, picks a start date range and attaches up to six site photos, each with a preview, its size and a button to remove it.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A quote request form whose labels, hints and error messages are full French sentences, still readable at 320 px: nothing overflows, nothing is cut off, and each error is tied to its field.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • Visitors pick a package and tick options: the pre-tax total, VAT and total including tax update live, and the summary is sent with the contact form.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A short NPS survey: a 0 to 10 score as radio buttons, then a follow-up question adapted to whether the customer is a detractor, passive or promoter.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • An honest unsubscribe page: address prefilled from the link, choice between stopping everything or receiving less, optional reason and an undo.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component
  • A callback request form: French phone number checked and formatted, topic, working day and time slot, with explicit consent to the call.

    • Tailwind
    • React
    • CSS
    • WordPress
    Component