Skip to content

Commit ed6bdca

Browse files
committed
extract a form validation object working ep 42
1 parent 1c8bf05 commit ed6bdca

File tree

24 files changed

+72
-80
lines changed

24 files changed

+72
-80
lines changed

.idea/.gitignore

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/modules.xml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/organized-stuff.iml

Lines changed: 0 additions & 8 deletions
This file was deleted.

.idea/php.xml

Lines changed: 0 additions & 22 deletions
This file was deleted.

.idea/vcs.xml

Lines changed: 0 additions & 6 deletions
This file was deleted.

Core/router.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ public function route($uri, $method)
105105
// if ($route['middleware'] === 'email-confirmed') {
106106
// (new ConfirmedEmail)->handle();
107107
// }
108-
return require base_path($route['controller']);
108+
return require base_path('Http/controllers/' . $route['controller']);
109109
}
110110
}
111111

Http/Forms/LoginForm.php

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
<?php
2+
3+
namespace Http\Forms;
4+
5+
use Core\Validator;
6+
7+
class LoginForm
8+
{
9+
protected $errors = [];
10+
11+
public function validate($email, $password)
12+
{
13+
// validate the form inputs.
14+
15+
if (!Validator::email($email)) {
16+
$this->errors['email'] = 'Please enter a valid email address.';
17+
}
18+
19+
if (!Validator::string($password)) {
20+
$this->errors['password'] = 'Please provide a valid password.';
21+
}
22+
23+
// this return $errors array but we want boolean value
24+
return empty($this->errors);
25+
}
26+
27+
// this is a getter method to access the errors
28+
// we can use this method to get the errors after validation
29+
public function errors()
30+
{
31+
return $this->errors;
32+
}
33+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)