Make waitlist form send more reliably and show clear errors
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KDXAh86FTSBLqF8ohPqZ88
This commit is contained in:
1 file changed
+12
-6
+12
-6
@@ -187,7 +187,7 @@ var FORM_ENDPOINT = 'https://formspree.io/f/mljgogkr';
|
|||||||
btn=document.getElementById('send'),note=document.getElementById('note');
|
btn=document.getElementById('send'),note=document.getElementById('note');
|
||||||
document.getElementById('yr').textContent=new Date().getFullYear();
|
document.getElementById('yr').textContent=new Date().getFullYear();
|
||||||
if(!FORM_ENDPOINT){note.textContent='Demo mode: emails are not saved yet.';}
|
if(!FORM_ENDPOINT){note.textContent='Demo mode: emails are not saved yet.';}
|
||||||
function say(cls,t){msg.className=cls;msg.textContent=t;}
|
function say(cls,t){msg.className=cls;msg.textContent=t;msg.scrollIntoView({block:'nearest'});}
|
||||||
form.addEventListener('submit',function(e){
|
form.addEventListener('submit',function(e){
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
var v=email.value.trim();
|
var v=email.value.trim();
|
||||||
@@ -196,11 +196,17 @@ var FORM_ENDPOINT = 'https://formspree.io/f/mljgogkr';
|
|||||||
if(document.getElementById('website').value){say('ok','Thank you! You are on the list.');return;}
|
if(document.getElementById('website').value){say('ok','Thank you! You are on the list.');return;}
|
||||||
if(!FORM_ENDPOINT){say('ok','Thank you! You are on the list (demo, not saved).');form.reset();return;}
|
if(!FORM_ENDPOINT){say('ok','Thank you! You are on the list (demo, not saved).');form.reset();return;}
|
||||||
btn.disabled=true;say('','Sending...');
|
btn.disabled=true;say('','Sending...');
|
||||||
fetch(FORM_ENDPOINT,{method:'POST',headers:{'Content-Type':'application/json','Accept':'application/json'},
|
var data=new FormData();data.append('email',v);data.append('phone',document.getElementById('phone').value);
|
||||||
body:JSON.stringify({email:v,phone:document.getElementById('phone').value})})
|
fetch(FORM_ENDPOINT,{method:'POST',headers:{'Accept':'application/json'},body:data})
|
||||||
.then(function(r){if(!r.ok)throw new Error('bad status');say('ok','Thank you! You are on the list.');form.reset();})
|
.then(function(r){
|
||||||
.catch(function(){say('err','Something went wrong. Please check your internet and try again.');})
|
if(!r.ok){return r.text().then(function(t){throw new Error('Error '+r.status+' '+t.slice(0,120));});}
|
||||||
.then(function(){btn.disabled=false;});
|
say('ok','Thank you! You are on the list.');form.reset();
|
||||||
|
})
|
||||||
|
.catch(function(err){
|
||||||
|
say('err','Could not send. ('+(err&&err.message?err.message:'network problem')+') Please try again in a minute.');
|
||||||
|
if(window.console)console.error('Waitlist error:',err);
|
||||||
|
})
|
||||||
|
.then(function(){btn.disabled=false;msg.scrollIntoView({block:'nearest'});});
|
||||||
});
|
});
|
||||||
})();
|
})();
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
Reference in new issue
Block a user