Blog Sections Open
Requiring at Least One Contact Field in eForm
A practical eForm validation pattern for cases where the user may provide either phone or email, but not necessarily both.
Not every form should force users to fill every contact field. In many cases the real requirement is simpler: at least one reliable way to respond must be provided.
The source question asked how to make one of several fields mandatory, typically a phone or email field. That is a common eForm need and a good example of validation that is better expressed as one logical rule than as several isolated required fields.
The goal
Instead of marking every field as required, validate the group as a whole:
- email is present, or
- phone is present
Practical approach
Handle this in a custom validation step or callback before the form is accepted. If both fields are empty, return a validation message and preserve the entered values.
if (empty($fields['email']) && empty($fields['phone'])) {
$fields['validationmessage'] = 'Please provide at least one contact method.';
return false;
}
Why this is better than over-validating
Users complete forms more reliably when the rule matches the real business need. If one contact method is enough, forcing both only increases abandonment.
This small validation pattern is still useful in Evo projects that rely on classic eForm flows for callback requests, quote forms, and lead capture.
Using DocLister prepare to Enrich Rows with Data from Another Table
How to use DocLister’s prepare callback to attach related images or derived values from a custom table before the final row template renders.
Sending Email Attachments Safely Through MODxMailer
How to attach uploaded files to outgoing messages in Evolution CMS without breaking MODxMailer by passing the wrong value to AddAttachment.