Neuron-PHP

ContactFormValidator
in package

Validates contact form submissions against a form's configured field definitions.

Validation rules are built dynamically from each field's config (type, required, options, rules) using the Neuron\Validation validators, so any configurable field set is supported without per-form code.

Table of Contents

Methods

validate()  : array<string, string>
Validate submitted values against field definitions.
isValidPhone()  : bool
Lenient phone validation suitable for a public contact form.
validateField()  : string|null
Validate a single non-empty field value.

Methods

validate()

Validate submitted values against field definitions.

public validate(array<string|int, mixed> $fieldDefs, array<string|int, mixed> $values) : array<string, string>
Parameters
$fieldDefs : array<string|int, mixed>

List of field definition arrays from config

$values : array<string|int, mixed>

Submitted values keyed by field name

Return values
array<string, string>

Map of field name => error message (empty when valid)

isValidPhone()

Lenient phone validation suitable for a public contact form.

private isValidPhone(string $value) : bool

Accepts common formats (parentheses, spaces, dashes, dots, optional leading +/country code) by checking the digit count rather than enforcing one rigid layout.

Parameters
$value : string
Return values
bool

validateField()

Validate a single non-empty field value.

private validateField(array<string|int, mixed> $field, string $label, string $value) : string|null
Parameters
$field : array<string|int, mixed>

Field definition

$label : string

Display label

$value : string

Submitted value

Return values
string|null

Error message, or null when valid

On this page

Search results