Phone field with country code in WordPress
A phone field with a country picker: the number is formatted while typing, its length is checked and it is sent in international format.
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
The code in WordPress
<?php
/**
* Plugin Name: Forge, Téléphone avec indicatif pays
* Description: Un champ téléphone avec choix du pays : le numéro se met en forme pendant la saisie, sa longueur est vérifiée et il est envoyé au format international. Ajoute la composition « Téléphone avec indicatif pays » à 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-telephone-indicatif
*<!-- wp:html -->
<form class="cti" data-cti data-cti-rules="{"FR":{"code":"33","groups":[2,2,2,2,2],"lengths":[10],"trunk":true,"example":"06 12 34 56 78"},"BE":{"code":"32","groups":[4,2,2,2],"lengths":[9,10],"trunk":true,"example":"0470 12 34 56"},"CH":{"code":"41","groups":[3,3,2,2],"lengths":[10],"trunk":true,"example":"079 123 45 67"},"LU":{"code":"352","groups":[3,3,3],"lengths":[6,7,8,9],"trunk":false,"example":"621 123 456"},"CA":{"code":"1","groups":[3,3,4],"lengths":[10],"trunk":false,"example":"514 555 0123"}}" novalidate aria-labelledby="cti-titre">
<h2 class="cti-title" id="cti-titre">Être rappelé par un conseiller</h2>
<fieldset class="cti-fs">
<legend class="cti-legend">Numéro de téléphone</legend>
<div class="cti-row">
<div class="cti-col cti-col--country">
<label class="cti-small" for="cti-pays">Pays</label>
<select class="cti-control" id="cti-pays" name="pays" autocomplete="tel-country-code">
<option value="FR">France (+33)</option>
<option value="BE">Belgique (+32)</option>
<option value="CH">Suisse (+41)</option>(() => {
if (!document.querySelector(".cti")) return;
document.querySelectorAll("[data-cti]").forEach((root) => {
const on = (el, type, fn) => el.addEventListener(type, fn);
const form = root;
const rules = JSON.parse(form.dataset.ctiRules);
const country = form.querySelector("#cti-pays");
const input = form.querySelector("#cti-numero");
const help = form.querySelector("[data-cti-help]");
const e164 = form.querySelector("[data-cti-e164]");
const status = form.querySelector("[data-cti-status]");
const rule = () => rules[country.value];:root {
--cti-card: #ffffff;
--cti-text: #1a2230;
--cti-muted: #4a5466;
--cti-line: #c8d0dc;
--cti-field: #ffffff;
--cti-accent: #3730a3;
--cti-accent-text: #ffffff;
--cti-error: #b91c1c;
--demo-champ-telephone-indicatif-bg: #eceef5;
--demo-champ-telephone-indicatif-text: #1a2230;
}Free component: copy it freely, including for commercial projects.
Other forms and inputs components in WordPress
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

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

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

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

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

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