Created
May 6, 2021 21:29
-
-
Save KravMaguy/0917692c33c75cb2341fcf929233c2e9 to your computer and use it in GitHub Desktop.
Trying to send form data to acculynx server from the client side
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 | |
include 'secrets.php'; | |
add_action( 'wp_head', 'cf7_form_send_to_acculynx' ); | |
function cf7_form_send_to_acculynx() { | |
?> | |
<script> | |
document.addEventListener("wpcf7mailsent", function (event) { | |
const details = event.detail.inputs; | |
const name = details[0].value; | |
const email = details[1].value; | |
const phone = details[2].value; | |
const address = details[3].value; | |
const message = details[4].value; | |
const key=<?=$apiKey;?> | |
const url="https://api.acculynx.com/api/v1/leads" | |
fetch(url, { | |
headers: { "Content-Type": "application/json; charset=utf-8", "Authorization": "Bearer "+key, "mode": "no-cors", }, | |
method: 'POST', | |
body: JSON.stringify({ | |
firstName: name, | |
emailAdress: email, | |
phoneNumber1: phone, | |
jobCategory: "residential", | |
street: address, | |
notes: message, | |
}) | |
}) | |
.then(response => response.json()) | |
.then(success => { | |
console.log(success); | |
}) | |
.catch(err => console.log(err)) | |
}); | |
</script> | |
<?php | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment