Created
November 5, 2017 12:33
-
-
Save woganmay/9f0b92bb3aff700263ca59751a20811f to your computer and use it in GitHub Desktop.
Simple HTTP POST request from an OctoberCMS form submission
This file contains 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 | |
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