Skip to content

WordPress forms — custom field validation broken

When a WordPress form custom validation hook stops firing — phone formats, business email rules, postal codes — the cause is usually a hook timing change, AJAX-vs-classic submission, or a renamed field reference.

Custom field validation on WordPress forms — reject free email providers, require Canadian postal code format, disallow disposable phone numbers — is one of the most common per-site customizations and one of the first things to break on plugin updates. The validation hook either fires at the wrong time, gets the wrong field reference, or runs only on classic POST submissions while the form uses AJAX. The user sees the form submit successfully with invalid data, and the validation never triggered.

What’s happening

Each form plugin exposes a validation hook: Gravity Forms uses gform_field_validation, WPForms uses wpforms_process_validate_<field_type>, Fluent Forms uses fluentform/validation_<field_type>, Ninja Forms uses ninja_forms_run_action_settings. The hook receives the field value and a result object; setting the result to invalid blocks the submission. When a custom validation hook was registered against a field by name and the field was renamed, the hook silently never matches. When AJAX submission was added to a form that previously used classic submission, validation hooks that returned wp_die() for errors stop working — AJAX expects a JSON response.

How to verify

Open the form on the front end with dev tools, submit invalid data, watch the AJAX response:

wp eval 'global $wp_filter; if (isset($wp_filter["gform_field_validation"])) { print_r(array_keys($wp_filter["gform_field_validation"]->callbacks)); }'
grep -r "gform_field_validation\|wpforms_process_validate\|fluentform_validation" wp-content/themes/active-theme/ wp-content/mu-plugins/ 2>/dev/null
tail -f wp-content/debug.log

A submission that returns 200 with success: true and no validation_messages confirms the hook never matched. A 500 confirms the hook fired but threw a fatal — usually a wp_die() left over from non-AJAX code.

The fix

  1. Match on stable identifiers: change custom validation from matching on field labels (which editors rename) to matching on field admin labels or IDs. In Gravity Forms, target $field->id; in WPForms, target $field['id'] and $field['type'].
  2. Return, do not die: in AJAX submissions, never call wp_die() from a validation hook. Set the result object’s is_valid to false and provide a message — the plugin handles the JSON response.
  3. Confirm hook timing: validation hooks in most plugins run on _validate_* actions. If you registered against _after_submission, validation is too late to block. Move to the validate hook.
  4. Test classic and AJAX: many sites enable AJAX submission via a setting, then forget. Test both — disable AJAX temporarily and resubmit invalid data. If validation now fires, the AJAX response handler is the gap.
  5. Snippet versioning: keep custom validation in a mu-plugin file (e.g. mu-plugins/form-validation.php) with a version comment. After every form plugin update, run a known-invalid submission to confirm the hook still matches.
  6. Server-side only: do not rely on JavaScript validation alone. Bots POST directly. Every rule must enforce server-side or it does not enforce at all.

For WordPress sites with complex validation tied to compliance (financial services, regulated industries), keeping these rules working through plugin updates is part of our enterprise WordPress hosting scope. To inventory and harden your custom validation, book a scoping call.