diff --git a/src/Controller/OutletController.php b/src/Controller/OutletController.php index eb22b2cb..b373f3da 100644 --- a/src/Controller/OutletController.php +++ b/src/Controller/OutletController.php @@ -161,21 +161,34 @@ class OutletController extends BaseController $em = $this->getDoctrine()->getManager(); $obj = new Outlet(); - $this->setObject($obj, $req); - - // validate - $errors = $validator->validate($obj); - // initialize error list $error_array = []; - // add errors to list - foreach ($errors as $error) { - $error_array[$error->getPropertyPath()] = $error->getMessage(); + // check if lat and lng are provided + if (empty($req->request->get('coord_lng')) || empty($req->request->get('coord_lat'))) + { + $error_array['coordinates'] = 'No map coordinates provided. Please click on a location on the map.'; } + if (empty($error_array)) + { + // set object + $this->setObject($obj, $req); + + // validate + $errors = $validator->validate($obj); + + // add errors to list + foreach ($errors as $error) + { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + } + + // check if any errors were found - if (!empty($error_array)) { + if (!empty($error_array)) + { // return validation failure response return $this->json([ 'success' => false, diff --git a/src/Entity/Outlet.php b/src/Entity/Outlet.php index 929b9b35..6ed4d3e9 100644 --- a/src/Entity/Outlet.php +++ b/src/Entity/Outlet.php @@ -26,12 +26,14 @@ class Outlet // name of enrollee /** * @ORM\Column(type="string", length=80) + * Assert\NotBlank() */ protected $name; // address /** * @ORM\Column(type="string", length=80) + * Assert\NotBlank() */ protected $address; @@ -45,18 +47,21 @@ class Outlet // this is displayed in a textarea /** * @ORM\Column(type="string", length=200) + * Assert\NotBlank() */ protected $contact_nums; // opening time /** * @ORM\Column(type="time") + * Assert\NotBlank() */ protected $time_open; // closing time /** * @ORM\Column(type="time") + * Assert\NotBlank() */ protected $time_close; diff --git a/templates/outlet/form.html.twig b/templates/outlet/form.html.twig index e926b6a3..27ba76e7 100644 --- a/templates/outlet/form.html.twig +++ b/templates/outlet/form.html.twig @@ -92,7 +92,7 @@
-
+