diff --git a/FreshdeskShim/src/Controller/FDShim_Controller.php b/FreshdeskShim/src/Controller/FDShim_Controller.php
index 722c708..570c921 100644
--- a/FreshdeskShim/src/Controller/FDShim_Controller.php
+++ b/FreshdeskShim/src/Controller/FDShim_Controller.php
@@ -9,7 +9,12 @@ use Symfony\Component\HttpFoundation\Request;
class FDShim_Controller extends ControllerBase {
public function fd_route(Request $request) {
if ($request->isMethod('POST')) {
- $postData = $request->request->all();
+ //$postData = $request->request->all();
+
+ // Data Validation
+ if (!isset($request['name']) || !isset($request['phone']) || !isset($request['email'])) {
+ return new JsonResponse(['error' => 'Bad Request'], 400);
+ }
// Initial variables
$apiUrl = 'https://jvmanufacturing-help.freshdesk.com/api/v2/tickets';
@@ -19,11 +24,34 @@ class FDShim_Controller extends ControllerBase {
'Content-Type: multipart/form-data',
'Authorization: ' . $apiKey
];
+ $descriptionString =
+ '
Name: ' . $request['name'] . '
' .
+ 'Date: ' . $request['date'] . '
' .
+ 'Phone: ' . $request['phone_num'] . '
' .
+ 'Hinge Type: ' . $request['hinge_type'] . '
' .
+ 'Ceiling Greater than 14ft: ' . $request['ceiling_height'] . '
' .
+ 'Loading Dock: ' . $request['loading_dock'] . '
' .
+ 'Basement Under Baler: ' . $request['baler_over_basement'] . '
' .
+ 'Voltage: ' . $request['voltage'] . '
';
+
+ // Converting the POST request data into the correct format for Fresdesk ticket creation
+ $postData = [
+ 'name' => $request['name'],
+ 'email' => $request['email'],
+ 'phone' => $request['phone'],
+ 'subject' => '[Webform Submission] ' . $request['name'] . ' Baler Request',
+ 'description' => $descriptionString,
+ 'attachments[]' => $request['attachments[]'],
+ 'status' => '2',
+ 'priority' => '1',
+ 'group' => '154000339633'
+ ];
+
// cURL Options
curl_setopt($fd, CURLOPT_RETURNTRANSFER, true);
curl_setopt($fd, CURLOPT_POST, true);
- curl_setopt($fd, CURLOPT_POSTFIELDS, http_build_query($postData));
+ curl_setopt($fd, CURLOPT_POSTFIELDS, $postData);
curl_setopt($fd, CURLOPT_HTTPHEADER, $headers);
$response = curl_exec($fd);