Branchwell

Lightwell / website · hellolightwell.com / public / careers.js

1(function(){var f=document.getElementById('cr-form');if(!f)return;var m=document.getElementById('cr-msg');
2f.addEventListener('submit',function(e){e.preventDefault();
3var E=f.elements,n=(E['name'].value||'').trim(),em=(E['email'].value||'').trim(),t=E['request'].value.trim();
4if(!n){m.textContent='Please add your name.';return;}
5if(!/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(em)){m.textContent='Please add a valid email.';return;}
6if(!t){m.textContent='Please write a short message.';return;}
7var b=f.querySelector('button');b.disabled=true;m.textContent='Sending…';
8fetch('/api/request',{method:'POST',headers:{'content-type':'application/json'},body:JSON.stringify({request:'Name: '+n+'\nEmail: '+em+'\n\n'+t,name:n,email:em,message:t,site:location.hostname,website:E['website'].value})})
9.then(function(r){if(!r.ok)throw 0;f.reset();m.textContent='Thanks. We got your note and will be in touch about joining our team.';})
10.catch(function(){m.textContent='That didn’t go through. Please try again in a minute.';})
11.then(function(){b.disabled=false;});});})();