Script now complete

This commit is contained in:
eoghan.conlon 2023-08-07 18:49:15 +01:00
parent 9e20464bbd
commit 325e3b8dd3

View file

@ -17,13 +17,10 @@
<input type="email" id="mail" name="email" /> <br /> <input type="email" id="mail" name="email" /> <br />
<input type="submit" value="Submit" /> <input type="submit" value="Submit" />
</form> </form>
<p id="formStatus"></p>
<footer> <footer>
UL Computer Society 2023-<span id="year">2023</span> UL Computer Society 2023-<span id="year">2023</span>
</footer> </footer>
</body>
<script>
document.getElementById('year').textContent = new Date().getFullYear().toString()
</script>
<script> <script>
const formEl = document.getElementById('register'); const formEl = document.getElementById('register');
formEl.addEventListener('submit', (listener) => formHandler(listener)); formEl.addEventListener('submit', (listener) => formHandler(listener));
@ -33,7 +30,23 @@
const formData = new FormData(formEl); const formData = new FormData(formEl);
const email = formData.get("email"); const email = formData.get("email");
const object = {email: email}; const object = {email: email};
alert(JSON.stringify(object)); fetch('https://api.account.skynet.ie/ldap/new/email', {
method: 'POST',
body: JSON.stringify(object),
mode: "cors"
}).then(res => {
if(res.status === 200) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: green; color: white'>Success</span>";
} else if (res.status === 500) {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure</span>";
} else {
document.getElementById('formStatus').innerHTML = "<span style='background-color: red; color: white'>Failure: Failed to communicate to server</span>";
}
}).catch(() => document.getElementById('formStatus').innerHTML = "<span style='background-color: yellow; color: black'>Please try again</span>");
} }
</script> </script>
</body>
<script>
document.getElementById('year').textContent = new Date().getFullYear().toString()
</script>
</html> </html>