mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
FIX Trim recipient email addresses before write
This commit is contained in:
parent
575d1f99a4
commit
59cd87d842
@ -116,6 +116,17 @@ class EmailRecipient extends DataObject
|
|||||||
DB::query("UPDATE \"UserDefinedForm_EmailRecipient\" SET \"FormClass\" = 'Page' WHERE \"FormClass\" IS NULL");
|
DB::query("UPDATE \"UserDefinedForm_EmailRecipient\" SET \"FormClass\" = 'Page' WHERE \"FormClass\" IS NULL");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function onBeforeWrite()
|
||||||
|
{
|
||||||
|
parent::onBeforeWrite();
|
||||||
|
|
||||||
|
// email addresses have trim() applied to them during validation for a slightly nicer UX
|
||||||
|
// apply trim() here too before saving to the database
|
||||||
|
$this->EmailAddress = trim($this->EmailAddress);
|
||||||
|
$this->EmailFrom = trim($this->EmailFrom);
|
||||||
|
$this->EmailReplyTo = trim($this->EmailReplyTo);
|
||||||
|
}
|
||||||
|
|
||||||
public function summaryFields()
|
public function summaryFields()
|
||||||
{
|
{
|
||||||
$fields = parent::summaryFields();
|
$fields = parent::summaryFields();
|
||||||
|
@ -38,4 +38,16 @@ class EmailRecipientTest extends SapphireTest
|
|||||||
$recipient->EmailFrom = 'test@example.com';
|
$recipient->EmailFrom = 'test@example.com';
|
||||||
$recipient->write();
|
$recipient->write();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEmailAddressesTrimmed()
|
||||||
|
{
|
||||||
|
$recipient = new EmailRecipient();
|
||||||
|
$recipient->EmailAddress = 'test1@example.com ';
|
||||||
|
$recipient->EmailFrom = 'test2@example.com ';
|
||||||
|
$recipient->EmailReplyTo = 'test3@example.com ';
|
||||||
|
$recipient->write();
|
||||||
|
$this->assertSame('test1@example.com', $recipient->EmailAddress);
|
||||||
|
$this->assertSame('test2@example.com', $recipient->EmailFrom);
|
||||||
|
$this->assertSame('test3@example.com', $recipient->EmailReplyTo);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user