From a1f0f2f45df00a539b578f1491cbca5ef15b1bf6 Mon Sep 17 00:00:00 2001 From: botzko Date: Fri, 21 Feb 2020 23:55:38 +0000 Subject: [PATCH 1/2] Form validation should throw ValidationException instead of calling unexisting method "addErrorMessage()" --- docs/en/02_Developer_Guides/03_Forms/01_Validation.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/docs/en/02_Developer_Guides/03_Forms/01_Validation.md b/docs/en/02_Developer_Guides/03_Forms/01_Validation.md index 3b71eab6c..990907b9b 100644 --- a/docs/en/02_Developer_Guides/03_Forms/01_Validation.md +++ b/docs/en/02_Developer_Guides/03_Forms/01_Validation.md @@ -163,9 +163,9 @@ class Page_Controller extends ContentController $check = Member::get()->filter('Email', $data['Email'])->first(); if ($check) { - $form->addErrorMessage('Email', 'This email already exists', 'bad'); - - return $this->redirectBack(); + $validationResult = new ValidationResult(); + $validationResult->addFieldError('Email', 'This email already exists'); + throw new ValidationException($validationResult); } From 1d859815378bc7b1c18fa6362d6c48db28b78b49 Mon Sep 17 00:00:00 2001 From: tdenev Date: Tue, 7 Apr 2020 22:46:32 +0100 Subject: [PATCH 2/2] Refactoring the form validation in the action to be more readable and in the SS standards based on the code review --- docs/en/02_Developer_Guides/03_Forms/01_Validation.md | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/en/02_Developer_Guides/03_Forms/01_Validation.md b/docs/en/02_Developer_Guides/03_Forms/01_Validation.md index 990907b9b..32b4d451d 100644 --- a/docs/en/02_Developer_Guides/03_Forms/01_Validation.md +++ b/docs/en/02_Developer_Guides/03_Forms/01_Validation.md @@ -165,7 +165,9 @@ class Page_Controller extends ContentController if ($check) { $validationResult = new ValidationResult(); $validationResult->addFieldError('Email', 'This email already exists'); - throw new ValidationException($validationResult); + $form->setSessionValidationResult($validationResult); + $form->setSessionData($form->getData()); + return $this->redirectBack(); }