diff options
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');  | 
