diff --git a/src/Forms/MemberProfileValidator.php b/src/Forms/MemberProfileValidator.php index 586d46f..4bda0de 100644 --- a/src/Forms/MemberProfileValidator.php +++ b/src/Forms/MemberProfileValidator.php @@ -84,14 +84,15 @@ public function php($data) $isEmail = $field === 'Email'; $emailOK = !$isEmail; if ($isEmail) { - $existing = Member::get()->filter('Email:nocase', $data['Email']); + // Case-insensitive email lookup, not using LIKE so that underscores in emails aren't treated as wildcards. + $filter = ['LOWER(Email) = LOWER(?)' => trim($data['Email'])]; // This ensures the existing member isn't the same as the current member, in case they're updating information. - if ($current = Security::getCurrentUser()) { - $existing = $existing->filter('ID:not', $current->ID); + $filter[] = ['ID <> ?' => $current->ID]; } - $emailOK = !$existing->first(); + + $emailOK = !DataObject::get_one(Member::class, $filter); } if ($other && (!$member || !$member->exists() || $other->ID != $member->ID) || !$emailOK) { $fieldInstance = $this->form->Fields()->dataFieldByName($field);