Lisää laskutoimituscaptcha tarjouspyyntölomakkeeseen
Satunnainen yhteenlaskukysymys (esim. "Paljonko on 3 + 5?") tarkistetaan sekä client- että serverpuolella. Vain sähköposti on nyt pakollinen kenttä. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
12
api.php
12
api.php
@@ -140,12 +140,20 @@ switch ($action) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Captcha
|
||||||
|
$captcha = trim($_POST['captcha'] ?? '');
|
||||||
|
$captchaAnswer = trim($_POST['captcha_answer'] ?? '');
|
||||||
|
if (!$captcha || $captcha !== $captchaAnswer) {
|
||||||
|
echo json_encode(['error' => 'Väärä vastaus varmistuskysymykseen.']);
|
||||||
|
exit;
|
||||||
|
}
|
||||||
|
|
||||||
// Validate
|
// Validate
|
||||||
$name = trim($_POST['name'] ?? '');
|
$name = trim($_POST['name'] ?? '');
|
||||||
$email = trim($_POST['email'] ?? '');
|
$email = trim($_POST['email'] ?? '');
|
||||||
|
|
||||||
if (!$name || !$email) {
|
if (!$email) {
|
||||||
echo json_encode(['error' => 'Nimi ja sähköposti ovat pakollisia.']);
|
echo json_encode(['error' => 'Sähköposti on pakollinen.']);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -65,8 +65,8 @@
|
|||||||
<!-- Yhteystiedot -->
|
<!-- Yhteystiedot -->
|
||||||
<div class="form-section-title">Yhteystiedot</div>
|
<div class="form-section-title">Yhteystiedot</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="name">Nimi *</label>
|
<label for="name">Nimi</label>
|
||||||
<input type="text" id="name" name="name" required>
|
<input type="text" id="name" name="name">
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="company">Yritys</label>
|
<label for="company">Yritys</label>
|
||||||
@@ -191,6 +191,14 @@
|
|||||||
<textarea id="message" name="message" rows="4" placeholder="Kerro lisää tarpeistasi: tehovaatimukset, aikataulu, erityistoiveet..."></textarea>
|
<textarea id="message" name="message" rows="4" placeholder="Kerro lisää tarpeistasi: tehovaatimukset, aikataulu, erityistoiveet..."></textarea>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<!-- Captcha -->
|
||||||
|
<div class="form-section-title">Varmistus</div>
|
||||||
|
<div class="form-group">
|
||||||
|
<label for="captcha" id="captcha-label"></label>
|
||||||
|
<input type="text" id="captcha" name="captcha" required autocomplete="off" inputmode="numeric" placeholder="Vastaus">
|
||||||
|
<input type="hidden" id="captcha-answer" name="captcha_answer">
|
||||||
|
</div>
|
||||||
|
|
||||||
<!-- Honeypot -->
|
<!-- Honeypot -->
|
||||||
<div style="display:none" aria-hidden="true">
|
<div style="display:none" aria-hidden="true">
|
||||||
<input type="text" name="website" tabindex="-1" autocomplete="off">
|
<input type="text" name="website" tabindex="-1" autocomplete="off">
|
||||||
@@ -282,6 +290,19 @@
|
|||||||
|
|
||||||
<script src="script.js"></script>
|
<script src="script.js"></script>
|
||||||
<script>
|
<script>
|
||||||
|
// Captcha
|
||||||
|
(function() {
|
||||||
|
function generateCaptcha() {
|
||||||
|
const a = Math.floor(Math.random() * 10) + 1;
|
||||||
|
const b = Math.floor(Math.random() * 10) + 1;
|
||||||
|
const answer = a + b;
|
||||||
|
document.getElementById('captcha-label').textContent = 'Paljonko on ' + a + ' + ' + b + '? *';
|
||||||
|
document.getElementById('captcha-answer').value = answer;
|
||||||
|
}
|
||||||
|
generateCaptcha();
|
||||||
|
window._refreshCaptcha = generateCaptcha;
|
||||||
|
})();
|
||||||
|
|
||||||
// Price Calculator
|
// Price Calculator
|
||||||
(function() {
|
(function() {
|
||||||
const form = document.getElementById('quote-form');
|
const form = document.getElementById('quote-form');
|
||||||
@@ -410,6 +431,17 @@
|
|||||||
const honeypot = form.querySelector('[name="website"]');
|
const honeypot = form.querySelector('[name="website"]');
|
||||||
if (honeypot && honeypot.value) return;
|
if (honeypot && honeypot.value) return;
|
||||||
|
|
||||||
|
// Captcha check
|
||||||
|
const captchaInput = document.getElementById('captcha').value.trim();
|
||||||
|
const captchaAnswer = document.getElementById('captcha-answer').value;
|
||||||
|
if (captchaInput !== captchaAnswer) {
|
||||||
|
status.textContent = 'Väärä vastaus varmistuskysymykseen.';
|
||||||
|
status.className = 'form-status form-status-error';
|
||||||
|
window._refreshCaptcha();
|
||||||
|
document.getElementById('captcha').value = '';
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const submitBtn = form.querySelector('.btn-submit');
|
const submitBtn = form.querySelector('.btn-submit');
|
||||||
submitBtn.disabled = true;
|
submitBtn.disabled = true;
|
||||||
status.textContent = 'Lähetetään...';
|
status.textContent = 'Lähetetään...';
|
||||||
@@ -431,6 +463,7 @@
|
|||||||
status.className = 'form-status form-status-success';
|
status.className = 'form-status form-status-success';
|
||||||
form.reset();
|
form.reset();
|
||||||
calculate();
|
calculate();
|
||||||
|
window._refreshCaptcha();
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(function() {
|
.catch(function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user