applicable-programming / darwin-cms

php OOP CMS - YouTube tutorial
28 stars 11 forks source link

Problem with validation #3

Open peyman6000 opened 2 years ago

peyman6000 commented 2 years ago

https://github.com/applicable-programming/darwin-cms/blob/d82ea322e0e33b052328f09878b54c5c8196d8f1/modules/dashboard/admin/controllers/DashboardController.php#L50

here we are $_SESSION['validationRules']['error'] and where we set it ? is it should be $_SESSION['validationRules']['errors'] ?

and another one is for first step to check password validation we set $validation->rule add rule for : [0] minimum [1] maximum [2] emptyspace [3] special charecter and rule array have 4 item after that again when we go to check the username rules item is : [0] minimum [1] maximum [2] emptyspace [3] special charecter [4] minimum [5] ValidateEmail

all of that check for username again

i think need be update ??

dakipro commented 2 years ago

That is an excellent point. I think I mentioned it somewhere in the video that it needs to be fixed, or maybe in comments. But you are right, validation either needs to be reset, or a new validation created, or some other way of starting from scratch for new validation rule. Good job!

peyman6000 commented 2 years ago

i try below code and works well

public function validate($value) { foreach ($this->rules as $key => $rule) { $ruleValidation = $rule->validateRule($value); if(!$ruleValidation){ $this->errors[]= $rule->getErrorMessage(); unset($this->rules[$key]); return false; } unset($this->rules[$key]); } return true; }