diff options
| author | David T. Sadler <davidtsadler@googlemail.com> | 2021-10-20 20:59:55 +0100 |
|---|---|---|
| committer | David T. Sadler <davidtsadler@googlemail.com> | 2021-10-20 20:59:55 +0100 |
| commit | d4122f116c937e0ec509d8cefe540146ec27a0cd (patch) | |
| tree | 481f90c4d774d32c89e612594158fe4a2d7328a4 /public/update | |
| parent | 1a112ab14becaf6d41cd34c176cbe563d4ca9742 (diff) | |
Validate fields
Diffstat (limited to 'public/update')
| -rw-r--r-- | public/update/index.php | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/public/update/index.php b/public/update/index.php index 50d0dcf..d194dbd 100644 --- a/public/update/index.php +++ b/public/update/index.php @@ -4,6 +4,8 @@ declare(strict_types=1); use DTS\BookmarkRepository; use DTS\Session; +use DTS\Validator; + use function DTS\Functions\respondAndExit; use function DTS\Functions\redirectAndExit; @@ -27,9 +29,19 @@ if ($bookmark === null) { respondAndExit(404, 'Not Found'); } -$bookmark->url = $_POST['url']; -$bookmark->title = $_POST['title']; -$bookmark->tag = $_POST['tag']; +$validator = new Validator($_REQUEST); + +if ($validator->errors->count()) { + $session->set('errors', $validator->errors); + + redirectAndExit("/edit?id=$bookmark->id"); +} + +$validated = $validator->validated; + +$bookmark->url = $validated->url; +$bookmark->title = $validated->title; +$bookmark->tag = $validated->tag; if (!$bookmarks->update($bookmark)) { respondAndExit(500, 'Internal Server Error'); |
