Created
September 13, 2023 15:25
-
-
Save ekmillard/c3ede2a2883def7814d13baad4ca2c6d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\Http; | |
class ProcessHubSpotController extends Controller | |
{ | |
/* | |
* | |
* ------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="hs_context" | |
{"embedAtTimestamp":"1694554327093","formDefinitionUpdatedAt":"1694551094920","lang":"en","embedType":"REGULAR","userAgent":"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36","pageTitle":"Form","pageUrl":"https://share.hsforms.com/1Hz_PaNeNTk2dqy3acPSOSA2fss5","isHubSpotCmsGeneratedPage":false,"canonicalUrl":"https://share.hsforms.com/1Hz_PaNeNTk2dqy3acPSOSA2fss5","hutk":"38899e9fb06019a5bd2769df076012ec","__hsfp":551255700,"__hssc":"251652889.4.1694553678530","__hstc":"251652889.38899e9fb06019a5bd2769df076012ec.1685993942896.1694465329127.1694553678530.20","formTarget":"#form-target","locale":"en","timestamp":1694554336325,"originalEmbedContext":{"portalId":"4096373","formId":"1f3fcf68-d78d-4e4d-9dab-2dda70f48e48","region":"na1","target":"#form-target","isBuilder":false,"isTestPage":false,"isPreview":false,"isMobileResponsive":true,"pageUrl":"https://share.hsforms.com/1Hz_PaNeNTk2dqy3acPSOSA2fss5"},"correlationId":"ec63d16b-bc65-40a6-9afb-22898ceb3cb5","renderedFieldsIds":["describe_the_process_to_be_completed_inside_the_hood___ex__solvent_mixing__slide_staining__dilution","will_any_of_the_above_chemical_s__be_heated_inside_of_the_hood__if_yes__which_and_explain_","describe_laboratory_environment_that_hood_is_to_be_placed_into___ex__acidic__clean_room__etc__","are_you_trying_to_protect_the_operator_or_process_","what_equipment_will_be_used_inside_of_the_hood__explain___ex__beakers__microscope__etc__","how_many_linear_feet_of_hood_space_are_required_for_your_application_","firstname","lastname","company","industry","phone","email","address","zip","state","country"],"captchaStatus":"NOT_APPLICABLE","emailResubscribeStatus":"NOT_APPLICABLE","isInsideCrossOriginFrame":false,"source":"forms-embed-1.3743","sourceName":"forms-embed","sourceVersion":"1.3743","sourceVersionMajor":"1","sourceVersionMinor":"3743","_debug_allPageIds":{},"_debug_embedLogLines":[{"clientTimestamp":1694554326886,"level":"INFO","message":"Retrieved pageContext values which may be overriden by the embed context: {\"pageTitle\":\"Form\",\"pageUrl\":\"https://share.hsforms.com/1Hz_PaNeNTk2dqy3acPSOSA2fss5\",\"userAgent\":\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36\",\"isHubSpotCmsGeneratedPage\":false}"},{"clientTimestamp":1694554327096,"level":"INFO","message":"Retrieved analytics values from API response which may be overriden by the embed context: {\"hutk\":\"38899e9fb06019a5bd2769df076012ec\",\"canonicalUrl\":\"https://share.hsforms.com/1Hz_PaNeNTk2dqy3acPSOSA2fss5\"}"}]} | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="describe_the_process_to_be_completed_inside_the_hood___ex__solvent_mixing__slide_staining__dilution" | |
TEST | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="will_any_of_the_above_chemical_s__be_heated_inside_of_the_hood__if_yes__which_and_explain_" | |
TEST | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="describe_laboratory_environment_that_hood_is_to_be_placed_into___ex__acidic__clean_room__etc__" | |
TEST | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="are_you_trying_to_protect_the_operator_or_process_" | |
TEST | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="what_equipment_will_be_used_inside_of_the_hood__explain___ex__beakers__microscope__etc__" | |
TEST | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="how_many_linear_feet_of_hood_space_are_required_for_your_application_" | |
TEST | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="firstname" | |
TET | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="lastname" | |
TT | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="company" | |
TEST | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="industry" | |
TEST | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="phone" | |
19196121639 | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="email" | |
[email protected] | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="address" | |
5908 Tall Pines Ct | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="zip" | |
27596 | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="state" | |
NC | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy | |
Content-Disposition: form-data; name="country" | |
United States | |
------WebKitFormBoundaryuVJ3SdmBDIE5e9iy-- | |
*/ | |
public function submit(Request $request) | |
{ | |
// Prepare the data for submission | |
$hubspotData = [ | |
"submittedAt" => time() * 1000, // Convert to milliseconds | |
"fields" => [ | |
[ | |
"objectTypeId" => "0-1", | |
"name" => "email", | |
"value" => $request->input('email') | |
], | |
[ | |
"objectTypeId" => "0-1", | |
"name" => "firstname", | |
"value" => $request->input('firstname') | |
], | |
// Add more fields as needed | |
[ | |
"objectTypeId" => "0-1", | |
"name" => "lastname", | |
"value" => $request->input('lastname') | |
], | |
[ | |
"objectTypeId" => "0-1", | |
"name" => "phonenumber", | |
"value" => $request->input('phonenumber') | |
], | |
// Add more fields here | |
], | |
"context" => [ | |
"hutk" => $request->cookie('hubspotutk'), // Include the hubspotutk cookie value | |
"pageUri" => $request->fullUrl(), | |
"pageName" => "Application Worksheet" | |
], | |
// Add legal consent options if required | |
]; | |
// Convert the data to JSON | |
$finalData = json_encode($hubspotData); | |
// Set the URL for HubSpot form submission | |
$url = 'https://api.hsforms.com/submissions/v3/integration/submit/4096373/1f3fcf68-d78d-4e4d-9dab-2dda70f48e48'; | |
// Set headers for the POST request | |
$headers = [ | |
'Content-Type: application/json', | |
]; | |
// Prepare options for the HTTP request | |
$options = [ | |
'headers' => $headers, | |
'body' => $finalData, | |
]; | |
// Send the HTTP POST request | |
$response = Http::post($url, $options); | |
// Handle the response | |
if ($response->successful()) { | |
// Successful submission | |
return redirect()->route('thank-you'); | |
} else { | |
// Failed submission | |
// Log the error or take appropriate action | |
return redirect()->back()->with('error', 'Failed to submit the form. Please try again later.'); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment