From b0bf2cb0835632e41080bf03ae4b1f26d5b199c9 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sat, 7 Oct 2023 10:57:55 -0400 Subject: [PATCH] WIP on form integration --- src/app/Handlers.php | 20 +++++++++++++ src/app/composer.json | 3 +- src/app/composer.lock | 69 ++++++++++++++++++++++++++++++++++++++++++- src/app/index.php | 4 ++- 4 files changed, 93 insertions(+), 3 deletions(-) diff --git a/src/app/Handlers.php b/src/app/Handlers.php index c1d196e..e209b46 100644 --- a/src/app/Handlers.php +++ b/src/app/Handlers.php @@ -107,4 +107,24 @@ class Handlers } } } + + /** POST|PATCH /request */ + public static function requestSave() + { + AppUser::require(); + + $form = request()->validate([ + 'requestId' => ['required', 'text'], + 'requestText' => ['required', 'text'], + 'status' => ['required', 'textOnly'], + 'recurType' => ['required', 'textOnly'], + 'recurCount' => 'number', + 'recurInterval' => 'textOnly', + ]); + if ($form) { + // valid + } else { + // errors + } + } } diff --git a/src/app/composer.json b/src/app/composer.json index 102a1b3..d2d0b0a 100644 --- a/src/app/composer.json +++ b/src/app/composer.json @@ -9,7 +9,8 @@ "guzzlehttp/psr7": "^2.6", "http-interop/http-factory-guzzle": "^1.2", "auth0/auth0-php": "^8.7", - "vlucas/phpdotenv": "^5.5" + "vlucas/phpdotenv": "^5.5", + "leafs/form": "^2.0" }, "autoload": { "psr-4": { diff --git a/src/app/composer.lock b/src/app/composer.lock index f74602b..f5f8833 100644 --- a/src/app/composer.lock +++ b/src/app/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "14643f9ff62f769d0dc92694ad541085", + "content-hash": "5cf05fa628183ad173a48e697e23513f", "packages": [ { "name": "auth0/auth0-php", @@ -885,6 +885,73 @@ ], "time": "2023-07-08T12:03:30+00:00" }, + { + "name": "leafs/form", + "version": "v2.0", + "source": { + "type": "git", + "url": "https://github.com/leafsphp/form.git", + "reference": "b724596da4f52b9dc7fe1ec0cdf12b4325f369c6" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/leafsphp/form/zipball/b724596da4f52b9dc7fe1ec0cdf12b4325f369c6", + "reference": "b724596da4f52b9dc7fe1ec0cdf12b4325f369c6", + "shasum": "" + }, + "require": { + "ext-json": "*" + }, + "require-dev": { + "friendsofphp/php-cs-fixer": "^3.0", + "pestphp/pest": "^1.22" + }, + "type": "library", + "autoload": { + "files": [ + "src/functions.php" + ], + "psr-4": { + "Leaf\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Michael Darko", + "email": "mickdd22@gmail.com", + "homepage": "https://mychi.netlify.app", + "role": "Developer" + } + ], + "description": "Simple straightup data validation", + "homepage": "https://leafphp.dev/modules/forms/", + "keywords": [ + "form", + "framework", + "leaf", + "php", + "validation" + ], + "support": { + "issues": "https://github.com/leafsphp/form/issues", + "source": "https://github.com/leafsphp/form/tree/v2.0" + }, + "funding": [ + { + "url": "https://github.com/leafsphp", + "type": "github" + }, + { + "url": "https://opencollective.com/leaf", + "type": "open_collective" + } + ], + "time": "2023-08-19T01:07:37+00:00" + }, { "name": "leafs/http", "version": "v2.2.3", diff --git a/src/app/index.php b/src/app/index.php index 110c2c7..9891274 100644 --- a/src/app/index.php +++ b/src/app/index.php @@ -30,7 +30,9 @@ app()->group('/legal', function () { app()->get('/terms-of-service', fn () => Handlers::render('legal/terms-of-service', 'Terms of Service')); }); app()->group('/request', function () { - app()->get('/{reqId}/edit', Handlers::requestEdit(...)); + app()->get( '/{reqId}/edit', Handlers::requestEdit(...)); + app()->post( '/request', Handlers::requestSave(...)); + app()->patch('/request', Handlers::requestSave(...)); }); app()->group('/user', function () { app()->get('/log-on', AppUser::logOn(...));