Skip to content

Forms

WAGE includes a built-in form system with components for rendering forms, plus a server-side handler for spam prevention, validation, email delivery, and file storage.

The Wage\FormField component handles all input types with consistent styling, labels, required indicators, and optional icons.

Props: label, name, type (text/email/tel/textarea/select/checkbox), placeholder, icon, required, options, rows, value, help

echo new \Wage\FormField( label: 'Name', name: 'name', required: true );
echo new \Wage\FormField( name: 'postcode', icon: 'map-pin', placeholder: 'Enter postcode' );
echo new \Wage\FormField( label: 'Subject', name: 'subject', type: 'select', options: [
'general' => 'General Enquiry',
'valuation' => 'Valuation Request',
] );
echo new \Wage\FormField( label: 'Message', name: 'message', type: 'textarea', rows: 6 );
echo new \Wage\FormField( type: 'checkbox', name: 'consent', placeholder: 'I agree to the terms' );

The Wage\Form component wraps a <form> element with automatic action URL (admin-post.php for POST), spam prevention fields (nonce, honeypot, Turnstile), and success/error status messages.

Props: name, method, action, class, content (closure)

echo new \Wage\Form(
name: 'contact',
content: function() {
echo new \Wage\FormField( label: 'Name', name: 'name', required: true );
echo new \Wage\FormField( label: 'Email', name: 'email', type: 'email', required: true );
echo new \Wage\FormField( label: 'Message', name: 'message', type: 'textarea' );
echo new \Wage\Button( label: 'Send Message', type: 'submit', variant: 'primary' );
},
);

The Form component automatically calls Wage\Forms::fields() (nonce, honeypot, Turnstile widget) and Wage\Forms::status() (success/error notices) — you do not need to add these manually.

Form registrations are auto-scanned from the child theme’s inc/forms/ folder. Each PHP file in the folder registers one form:

inc/forms/
├── contact.php # Registers the 'contact' form
└── postal-pack.php # Registers the 'postal-pack' form

Each file calls Wage\Forms::register():

inc/forms/contact.php
<?php
Wage\Forms::register( 'contact', [
'fields' => [ 'name', 'email', 'message' ],
'email_to' => 'info@example.co.uk',
] );

No manual require_once needed — Wage\App::load_forms() auto-scans the folder at boot.

WAGE uses Cloudflare Turnstile (free, privacy-friendly CAPTCHA alternative) for spam prevention.

  1. Log into Cloudflare Dashboard → Turnstile → Add Site
  2. Copy the Site Key and Secret Key
  3. Add keys to the child theme’s functions.php:
define('WAGE_TURNSTILE_SITE_KEY', 'your-site-key');
define('WAGE_TURNSTILE_SECRET_KEY', 'your-secret-key');

The Wage\Form component handles rendering the Turnstile widget and the Wage\Forms class validates the response server-side.

  • Server-side validation — required fields, email format, length limits
  • Email delivery — sends form data via wp_mail()
  • File storage — submissions saved to the data/ directory (protected from public access via .htaccess)
  • Honeypot field — hidden field to catch basic bots (in addition to Turnstile)