Skip to content

Commit 793e310

Browse files
committed
update
1 parent 0c59f9d commit 793e310

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

app/code/core/Mage/Contacts/controllers/IndexController.php

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -75,18 +75,21 @@ public function postAction()
7575
$postObject = new Varien_Object();
7676
$postObject->setData($post);
7777

78-
// check data
79-
$error = false;
8078
$validator = Validation::createValidator();
81-
if ($validator->validate(trim($post['name']), new Assert\Length(['min' => 1, 'max' => 255]))->count() > 0) {
82-
$error = true;
83-
} elseif ($validator->validate(trim($post['comment']), new Assert\Length(['min' => 1, 'max' => 2048]))->count() > 0) {
84-
$error = true;
85-
} elseif ($validator->validate(trim($post['email']), [new Assert\NotBlank(), new Assert\Email()])->count() > 0) {
86-
$error = true;
79+
$violations = [];
80+
$errors = new ArrayObject();
81+
82+
$violations[] = $validator->validate(trim($post['name']), new Assert\Length(['min' => 1, 'max' => 255]));
83+
$violations[] = $validator->validate(trim($post['comment']), new Assert\Length(['min' => 1, 'max' => 2048]));
84+
$violations[] = $validator->validate(trim($post['email']), new Assert\Length(['min' => 1, 'max' => 2048]));
85+
86+
foreach ($violations as $violation) {
87+
foreach ($violation as $error) {
88+
$errors->append($error->getMessage());
89+
}
8790
}
8891

89-
if ($error) {
92+
if (count($errors) !== 0) {
9093
Mage::throwException($this->__('Unable to submit your request. Please, try again later'));
9194
}
9295

0 commit comments

Comments
 (0)