From 6cc99d2ebe3075ea3966dc0962e295f76facff1f Mon Sep 17 00:00:00 2001 From: Miguel Nogueira Date: Fri, 9 Oct 2020 00:56:11 +0100 Subject: [PATCH] Prevent empty form creation --- app/Http/Controllers/FormController.php | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/app/Http/Controllers/FormController.php b/app/Http/Controllers/FormController.php index 27d40dd..4452ac5 100644 --- a/app/Http/Controllers/FormController.php +++ b/app/Http/Controllers/FormController.php @@ -33,6 +33,14 @@ class FormController extends Controller $this->authorize('create', Form::class); $fields = $request->all(); + if (count($fields) == 2) + { + // form is probably empty, since forms with fields will alawys have more than 2 items + + $request->session()->flash('error', 'Sorry, but you may not create empty forms.'); + return redirect()->to(route('showForms')); + } + $contextValidation = ContextAwareValidator::getValidator($fields, true, true); if (!$contextValidation->get('validator')->fails())