prevent spaces in emails

so this is not the first time a customer of mine is just copy pasting stuff in emails fields and somehow, a space at the end skips validation. this update ensure there is no space before or after the email, it would probably save a lot of time for everyone to have this build in.
it's probably better to fix it here rather than at form level because this also happens for csv imports etc
This commit is contained in:
Thomas Portelange 2021-03-19 10:11:02 +01:00 committed by GitHub
parent 358efdb51d
commit 0586c55e62
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -871,6 +871,11 @@ class Member extends DataObject
*/ */
public function onBeforeWrite() public function onBeforeWrite()
{ {
// Prevent spaces in emails
if($this->Email) {
$this->Email = trim($this->Email);
}
// If a member with the same "unique identifier" already exists with a different ID, don't allow merging. // If a member with the same "unique identifier" already exists with a different ID, don't allow merging.
// Note: This does not a full replacement for safeguards in the controller layer (e.g. in a registration form), // Note: This does not a full replacement for safeguards in the controller layer (e.g. in a registration form),
// but rather a last line of defense against data inconsistencies. // but rather a last line of defense against data inconsistencies.