Fix contact form submission errors and restore full functionality

- Fix JavaScript syntax errors preventing form submission
- Update reCAPTCHA configuration with working test keys
- Restore comprehensive spam protection (reCAPTCHA v3, AJAX validation, rate limiting)
- Switch from minified to source JS file to apply critical fixes
- Add missing security headers and form validation

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
root
2025-06-18 05:47:55 +00:00
parent cffe81f960
commit 0a3521a955
4 changed files with 71 additions and 24 deletions

View File

@@ -171,6 +171,21 @@ document.addEventListener('DOMContentLoaded', function() {
console.log('Enhanced animations initialized');
// Initialize reCAPTCHA and form tracking
let interactionScore = 0;
let formStartTime = Date.now();
// Track user interactions for bot detection
document.addEventListener('mousemove', () => interactionScore += 1);
document.addEventListener('keydown', () => interactionScore += 2);
document.addEventListener('click', () => interactionScore += 3);
// Set form timestamp
const timestampField = document.getElementById('form_timestamp');
if (timestampField) {
timestampField.value = formStartTime;
}
// Form Validation and Enhancement
const contactForm = document.querySelector('.contact-form form');
@@ -210,28 +225,47 @@ document.addEventListener('DOMContentLoaded', function() {
submitButton.textContent = 'Sending...';
submitButton.disabled = true;
// Submit form (you'll need to implement the backend handler)
fetch('contact-handler.php', {
method: 'POST',
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
showNotification('Message sent successfully! We\'ll get back to you soon.', 'success');
this.reset();
} else {
showNotification('There was an error sending your message. Please try again.', 'error');
}
})
.catch(error => {
console.error('Error:', error);
showNotification('There was an error sending your message. Please try again.', 'error');
})
.finally(() => {
// Execute reCAPTCHA and submit form
if (typeof grecaptcha !== 'undefined') {
grecaptcha.ready(() => {
grecaptcha.execute(window.recaptchaSiteKey, {action: 'contact_form'}).then((token) => {
// Add reCAPTCHA token and interaction data
formData.set('recaptcha_response', token);
formData.set('interaction_token', btoa(JSON.stringify({score: Math.min(interactionScore, 100), time: Date.now() - formStartTime})));
// Submit form
fetch('contact-handler.php', {
method: 'POST',
headers: {
'X-Requested-With': 'XMLHttpRequest'
},
body: formData
})
.then(response => response.json())
.then(data => {
if (data.success) {
showNotification('Message sent successfully! We\'ll get back to you soon.', 'success');
this.reset();
} else {
showNotification(data.message || 'There was an error sending your message. Please try again.', 'error');
}
})
.catch(error => {
console.error('Error:', error);
showNotification('There was an error sending your message. Please try again.', 'error');
})
.finally(() => {
submitButton.textContent = originalText;
submitButton.disabled = false;
});
});
});
} else {
// Fallback if reCAPTCHA not loaded
showNotification('Security verification not available. Please refresh the page.', 'error');
submitButton.textContent = originalText;
submitButton.disabled = false;
});
}
} else {
showNotification(errors.join('<br>'), 'error');
}