Skip to main content
Documentation/Developers/APIs/Forms/Form Field Validation Filter

Form Field Validation Filter

Add custom PHP validation with breakdance_form_validate_field. Validation errors prevent submission actions from running.

Validate a Field

breakdance_form_validate_field($fieldErrors, $field, $formId, $postId) receives WP_Error, field array, and integer element/document IDs. Return the error object:

PHP
add_filter('breakdance_form_validate_field', function ($errors, $field, $formId, $postId) {
    if ((int) $postId !== 123 || (int) $formId !== 7
        || ($field['advanced']['id'] ?? '') !== 'booking_code') {
        return $errors;
    }
    $value = (string) ($field['value'] ?? '');
    if ($value !== '' && !preg_match('/^[A-Z]{3}-[0-9]{4}$/D', $value)) {
        $errors->add('acme_booking_code', 'Use a code such as ABC-1234.');
    }
    return $errors;
}, 10, 4);

Replace IDs and booking_code. Empty values pass this example; use Required separately. The hook runs before built-in checks, excluding step/HTML fields. Records include type, value, label, advanced, and originalValue; preserve multi-value shapes.

This uses direct apply_filters; no automatic oxygen_form_validate_field alias is emitted.