Files
zaufane.pl/templates_user/contact-form.php

167 lines
6.5 KiB
PHP

<?php
if ( \S::get('action') == 'form_contact_mail' )
{
if ( $_SERVER["REQUEST_METHOD"] == "POST" )
{
$recaptchaSecret = '6Le9GhEqAAAAAKUCOPR9QGXs4G81OGZ2CxUOu7rW';
$recaptchaResponse = $_POST['g-recaptcha-response'];
// Verify reCAPTCHA
$recaptchaSecret = '6Lf1XC8sAAAAAIokP1OHFj8W-jdJp3xj6e0NYO6Z';
$recaptchaResponse = isset($_POST['g-recaptcha-response']) ? $_POST['g-recaptcha-response'] : null;
if ( $recaptchaResponse )
{
$response = file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret={$recaptchaSecret}&response={$recaptchaResponse}");
$responseKeys = json_decode($response, true);
// Ustawiamy próg (score 0.5 to standardowy środek)
$minScore = 0.5;
// Sprawdzamy czy sukces ORAZ czy wynik jest wystarczająco wysoki
if ( $responseKeys["success"] && isset($responseKeys["score"]) && $responseKeys["score"] >= $minScore )
{
$hubspot_url = "https://api.hsforms.com/submissions/v3/integration/submit/7094950/b007eef9-5fb5-4535-821a-da1560ce2861";
$hubspotutk = isset($_COOKIE['hubspotutk']) ? $_COOKIE['hubspotutk'] : null;
$postData = [
'fields' => [
[
'name' => 'firstname',
'value' => $_POST['name']
],
[
'name' => 'phone',
'value' => $_POST['phone'],
],
[
'name' => 'email',
'value' => $_POST['email'],
],
[
'name' => 'wiadomosc',
'value' => $_POST['form-message']
], [
'name' => 'LEGAL_CONSENT.subscription_type_8488293',
'value' => $_POST['checkbox-1'] ? 'true' : 'false'
],
],
'context' => [
'hutk' => $hubspotutk,
'pageUri' => 'https://zaufane.pl/',
'pageName' => 'zaufane.pl'
],
'legalConsentOptions' => [
'consent' => [
'content' => 'By submitting this form, you agree that we may use the data you provide to contact you with information related to your request/submission and the relevant zaufane.pl product. If you are a zaufane.pl member, you can control the messages you receive from zaufane.pl in your settings. If you are a guest, you can unsubscribe from zaufane.pl marketing emails at any time by clicking the unsubscribe link in the email. To learn more, see zaufane.pl Privacy Policy.',
'consentToProcess' => true,
'text' => 'I agree to the processing of my personal data by zaufane.pl.',
'communications' => [
[
'value' => true,
'subscriptionTypeId' => 7094950,
'text' => 'I agree to receive marketing communications from zaufane.pl.'
]
]
]
]
];
$jsonData = json_encode($postData);
// Initialize cURL
$ch = curl_init($hubspot_url);
// Set cURL options
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
// Execute cURL request
$response = curl_exec($ch);
// Check for errors
if ($response === false) {
$error = curl_error($ch);
echo "cURL Error: $error";
} else {
// Decode response
$responseData = json_decode($response, true);
if (isset($responseData['inlineMessage'])) {
echo "<div id='custom-contact-mail-response'><p>" . $responseData['inlineMessage'] . '</p></div>';
} else {
echo "<div id='custom-contact-mail-response'><p>" . $response . '</p></div>';
}
}
// Close cURL session
curl_close($ch);
?>
<script class="footer">
$(document).ready(function() {
$('#form-contact-mail').remove()
})
</script>
<?php
} else {
// echo 'reCAPTCHA verification failed. You might be a bot.';
}
} else {
// echo 'Please complete the CAPTCHA';
}
}
}
?>
<div class="contact-form-wrapper">
<form method="POST" action="<?php echo $_SERVER['REQUEST_URI']; ?>" id="form-contact-mail">
<input type="hidden" name="action" value="form_contact_mail">
<input type="hidden" name="g-recaptcha-response" id="g-recaptcha-response">
<div class="f-row">
<div class="tile">
<input type="text" name="name" id="form-name" placeholder="" required>
<label for="form-name">Imię</label>
</div>
<div class="tile">
<input type="text" name="phone" id="form-phone" placeholder="" required>
<label for="form-phone">Numer telefonu</label>
</div>
<div class="tile">
<input type="email" name="email" id="form-email" placeholder="" required>
<label for="form-email">Adres e-mail</label>
</div>
<div class="tile">
<input type="text" name="form-message" id="form-message" placeholder="" required>
<label for="form-message">Wiadomość</label>
</div>
</div>
<div class="checkbox-row">
<input type="checkbox" name="checkbox-1" id="checkbox-1" required>
<label for="checkbox-1">Wyrażam zgodę na przechowywanie i przetwarzanie moich danych osobowych przez firmę Zaufane.pl.<span class="hs-form-required">*</span></label>
</div>
<div class="tile small">W każdej chwili mogą Państwo zrezygnować z tych komunikatów. Aby uzyskać więcej informacji na temat sposobu rezygnacji z subskrypcji, naszych zasad ochrony prywatności oraz tego, w jaki sposób zobowiązujemy się do ochrony i poszanowania prywatności, należy zapoznać się z naszą Polityką Prywatności.</div>
<div class="btn-row">
<button type="submit" class="btn1">Prześlij</button>
</div>
</form>
</div>
<script src="https://www.google.com/recaptcha/api.js?render=6Lf1XC8sAAAAAP7HMxUHzpkPEePvi80eSZrcJH2l"></script>
<script>
document.getElementById('form-contact-mail').addEventListener('submit', function(e) {
e.preventDefault();
const siteKey = '6Lf1XC8sAAAAAP7HMxUHzpkPEePvi80eSZrcJH2l';
grecaptcha.ready(function() {
grecaptcha.execute(siteKey, {action: 'contact_form'}).then(function(token) {
document.getElementById('g-recaptcha-response').value = token;
document.getElementById('form-contact-mail').submit();
});
});
});
</script>