<?php
function submitFormResponse($formData) {
$apiKey = 'YOUR_API_KEY';
$domainId = 'your-domain-id';
$data = [
'form_response' => [
'domain_id' => $domainId,
'form_data' => $formData,
'form_type' => 'contact',
'source_url' => 'https://yourwebsite.com/contact',
'user_agent' => $_SERVER['HTTP_USER_AGENT'] ?? '',
'ip_address' => $_SERVER['REMOTE_ADDR'] ?? ''
]
];
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://yourdomain.com/api/v1/form_responses');
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($data));
curl_setopt($ch, CURLOPT_HTTPHEADER, [
'Content-Type: application/json',
'Authorization: Bearer ' . $apiKey
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($httpCode === 201) {
$result = json_decode($response, true);
return $result;
} else {
throw new Exception('API request failed: ' . $response);
}
}
// Usage
try {
$result = submitFormResponse([
'name' => 'John Doe',
'email' => 'john@example.com',
'phone' => '+1234567890',
'message' => 'I\'m interested in your services'
]);
echo "Form submitted successfully!";
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
?>