mirror of
https://github.com/silverstripe/silverstripe-userforms.git
synced 2024-10-22 17:05:42 +02:00
Merge pull request #536 from solnet-aquarium/emailValidation
This commit is contained in:
commit
b068bf65bf
@ -446,4 +446,33 @@ class UserDefinedForm_EmailRecipient extends DataObject
|
|||||||
|
|
||||||
return $templates;
|
return $templates;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validate that valid email addresses are being used
|
||||||
|
*
|
||||||
|
* @return ValidationResult
|
||||||
|
*/
|
||||||
|
public function validate() {
|
||||||
|
$result = parent::validate();
|
||||||
|
$checkEmail = array(
|
||||||
|
'EmailAddress' => 'EMAILADDRESSINVALID',
|
||||||
|
'EmailFrom' => 'EMAILFROMINVALID',
|
||||||
|
'EmailReplyTo' => 'EMAILREPLYTOINVALID',
|
||||||
|
);
|
||||||
|
foreach ($checkEmail as $check => $translation) {
|
||||||
|
if ($this->$check) {
|
||||||
|
//may be a comma separated list of emails
|
||||||
|
$addresses = explode(',', $this->$check);
|
||||||
|
foreach ($addresses as $address) {
|
||||||
|
$trimAddress = trim($address);
|
||||||
|
if ($trimAddress && !Email::is_valid_address($trimAddress)) {
|
||||||
|
$error = _t("UserDefinedForm_EmailRecipient.$translation",
|
||||||
|
"Invalid email address $trimAddress");
|
||||||
|
$result->error($error . " ($trimAddress)");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -236,6 +236,9 @@ en:
|
|||||||
EMAILDETAILSTAB: 'Email Details'
|
EMAILDETAILSTAB: 'Email Details'
|
||||||
PLURALNAME: 'User Defined Form Email Recipients'
|
PLURALNAME: 'User Defined Form Email Recipients'
|
||||||
SINGULARNAME: 'User Defined Form Email Recipient'
|
SINGULARNAME: 'User Defined Form Email Recipient'
|
||||||
|
EMAILADDRESSINVALID: '"EmailAddress" is not valid'
|
||||||
|
EMAILFROMINVALID: '"Email From" is not valid'
|
||||||
|
EMAILREPLYTOINVALID: '"Email Reply To" is not valid'
|
||||||
UserDefinedForm_EmailRecipientCondition:
|
UserDefinedForm_EmailRecipientCondition:
|
||||||
PLURALNAME: 'User Defined Form Email Recipient Conditions'
|
PLURALNAME: 'User Defined Form Email Recipient Conditions'
|
||||||
SINGULARNAME: 'User Defined Form Email Recipient Condition'
|
SINGULARNAME: 'User Defined Form Email Recipient Condition'
|
||||||
|
@ -455,4 +455,24 @@ class UserDefinedFormTest extends FunctionalTest
|
|||||||
$this->assertNotContains('<p></p>', $body);
|
$this->assertNotContains('<p></p>', $body);
|
||||||
$this->assertNotContains('</p><p>Thank you for filling it out</p>', $body);
|
$this->assertNotContains('</p><p>Thank you for filling it out</p>', $body);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function testEmailAddressValidation()
|
||||||
|
{
|
||||||
|
$this->logInWithPermission('ADMIN');
|
||||||
|
|
||||||
|
// test invalid email addresses fail validation
|
||||||
|
$recipient = $this->objFromFixture('UserDefinedForm_EmailRecipient',
|
||||||
|
'invalid-recipient-list');
|
||||||
|
$result = $recipient->validate();
|
||||||
|
$this->assertFalse($result->valid());
|
||||||
|
$this->assertContains('filtered.example.com', $result->message());
|
||||||
|
$this->assertNotContains('filtered2@example.com', $result->message());
|
||||||
|
|
||||||
|
// test valid email addresses pass validation
|
||||||
|
$recipient = $this->objFromFixture('UserDefinedForm_EmailRecipient',
|
||||||
|
'valid-recipient-list');
|
||||||
|
$result = $recipient->validate();
|
||||||
|
$this->assertTrue($result->valid());
|
||||||
|
$this->assertEmpty($result->message());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -237,6 +237,16 @@ UserDefinedForm_EmailRecipient:
|
|||||||
CustomRules: =>UserDefinedForm_EmailRecipientCondition.group-equals-rule, =>UserDefinedForm_EmailRecipientCondition.group-not-equals-rule
|
CustomRules: =>UserDefinedForm_EmailRecipientCondition.group-equals-rule, =>UserDefinedForm_EmailRecipientCondition.group-not-equals-rule
|
||||||
CustomRulesCondition: 'Or'
|
CustomRulesCondition: 'Or'
|
||||||
|
|
||||||
|
valid-recipient-list:
|
||||||
|
EmailAddress: filtered@example.com, filtered2@example.com
|
||||||
|
EmailSubject: Email Subject
|
||||||
|
EmailFrom: no-reply@example.com
|
||||||
|
|
||||||
|
invalid-recipient-list:
|
||||||
|
EmailAddress: filtered.example.com, filtered2@example.com
|
||||||
|
EmailSubject: Email Subject
|
||||||
|
EmailFrom: no-reply@example.com
|
||||||
|
|
||||||
UserDefinedForm:
|
UserDefinedForm:
|
||||||
basic-form-page:
|
basic-form-page:
|
||||||
Content: '<p>Here is my form</p><p>$UserDefinedForm</p><p>Thank you for filling it out</p>'
|
Content: '<p>Here is my form</p><p>$UserDefinedForm</p><p>Thank you for filling it out</p>'
|
||||||
|
Loading…
Reference in New Issue
Block a user