Good day, until I can figure out what the problem is. There are 2 classes, each of which implements data validation, one is to check if the field is empty, etc., and the other is responsible for the correctness of the answers in these fields. The problem is as follows.

I use the method of the Validator class somehow:

$this->validate->validate($_POST,[ 'full_name' => 'isNotEmpty', 'email' => 'isNotEmpty,isEmail', ]); 

The first argument is the name of the input, the second is the name of the function that will check it.

Everything works fine if the field is empty - I get an error, if not, everything is fine, but when I try to use the custom method to check the correctness of the answers - the first method is simply ignored, it does not even start, nothing at all.

The method I call is the same

  $this->custom->check($_POST, [ 'question_1' => '48', 'question_2' => 'Алгоритм', ]); 

Here it is the same, only the second parameter is not a function, but simply a value which must coincide with the value of the input question_1 or 2.

The first method looks like this: Validate method

The second method looks like this:

Check method

When you call one of them, everything works, when you call one by one, only the one that comes second (!), Only he, works.

It looks like this:

  $this->validate->validate($_POST,[ 'full_name' => 'isNotEmpty', 'group' => 'isNotEmpty', 'question_1' => 'isNotEmpty', 'question_2' => 'isNotEmpty', 'question_3' => 'isNotEmpty' ]); $this->custom->check($_POST, [ 'question_1' => '3', 'question_2' => 'Пространственный контиинум', 'question_3' => '1' ]); 

Here, for some reason, custom-> check will be executed.

If you swap them, validate-> validate is executed.

Maybe a mistake in some trifles, but I still do not understand what it is.

If you make all the methods of the second static controller, everything will work.

Question: Why is the second method called first, and why is the first ignored?

UPD 1.

Found a mistake, she's

  Session::put('errors', $this->errors); 

I do not really understand why, but if you remove this line, and for example, make var_dump $ this-> errors, then everything will be ok. While decided crutches, namely added to the session not errors, a errors_test for the test.

  • @arnial, I attached them in a post. There are links to pastebin. - sasha_t
  • @arnial; Yes, of course, second. - sasha_t
  • @arnial, Sorjan so long - tried to insert a link in the area for the code. Now they are. - sasha_t
  • In the validate method, in the 26th and 33rd lines, keys are passed to methods for validation and not data. Not sure what the error is in this, but it is very strange. - Arnial
  • You can find out what the correct method will do if, before calling the check method, the field was incorrect (due to validate)? (Possible error: check does not pay attention to the current state of the field and always calls correct / incorrect methods) - Arnial

0