Skip to content

Instantly share code, notes, and snippets.

@woganmay
Created November 5, 2017 12:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woganmay/9f0b92bb3aff700263ca59751a20811f to your computer and use it in GitHub Desktop.
Save woganmay/9f0b92bb3aff700263ca59751a20811f to your computer and use it in GitHub Desktop.
Simple HTTP POST request from an OctoberCMS form submission
<?php
function onStart()
{
$flow = curl_init("https://prod-22.westeurope.logic.azure.com:443/...");
curl_setopt($flow, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($flow, CURLOPT_POST, TRUE);
curl_setopt($flow, CURLOPT_HTTPHEADER, [
'Content-Type: application/json'
]);
curl_setopt($flow, CURLOPT_POSTFIELDS, json_encode([
'name' => post('name'),
'email' => post('email'),
'message' => post('message'),
]));
$flowResult = curl_exec($flow);
if (curl_getinfo($flow, CURLINFO_HTTP_CODE) == 202)
{
// The input has been accepted and the flow has started
$this->page['success'] = "Your message has been sent, thanks!";
}
else
{
// There was a problem while trying to start the flow
$this->page['warning'] = "Apologies, it looks like there's a backend problem.";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment