Update Contact Form to use a dropdown for subject and proper links for Terms of Service and Privacy Policy

This commit is contained in:
2025-04-22 21:39:18 -08:00
parent e35e359f60
commit 999013d72e
9 changed files with 45 additions and 64 deletions

View File

@@ -1,37 +1,7 @@
/*
This grabs a querystring named topic and puts it in the subject of an email via the web form.
It goes through a few checks prior to inserting it.
- Filters out bad words
- Truncates to a maximum of 30 characters
TODO: Optionally check for allowed topics.
*/
window.addEventListener('DOMContentLoaded', async function () {
const FilterModule = await import('bad-words');
const voca = await import('voca');
const Filter = FilterModule.Filter;
if (typeof Filter !== 'function') {
console.error("bad-words: named export 'Filter' is not a constructor:", FilterModule);
return;
window.addEventListener('DOMContentLoaded', function(){
const selectElement = document.getElementById('subject') || false;
const topicParam = new URLSearchParams(window.location.search).get('topic') || false;
if ( selectElement !== false && topicParam !== false){
selectElement.value = topicParam;
}
const filter = new Filter();
const subjectEl = document.querySelector("form[name='contact'] input[name='subject']");
if (!subjectEl) return;
const topicParam = new URLSearchParams(window.location.search).get('topic') || 'none';
if (topicParam === 'none') return;
// Clean and truncate
const cleanedTopic = filter.clean(topicParam).substring(0, 30);
// Title case the cleaned topic
const titledTopic = voca.default.titleCase(cleanedTopic);
const currentSubject = subjectEl.value || 'none';
subjectEl.value = currentSubject.concat(" - ", titledTopic);
});
})