44 lines
No EOL
1.4 KiB
PHP
44 lines
No EOL
1.4 KiB
PHP
<section class="newsletter">
|
|
<h2>Newsletter</h2>
|
|
<div
|
|
x-data="{
|
|
btnMsg: 's\'inscrire',
|
|
submit(event) {
|
|
event.preventDefault()
|
|
|
|
const email = this.$refs.emailInput.value;
|
|
const emailRegex = /^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
|
|
if (emailRegex.test(email)) {
|
|
const options = {
|
|
method: 'POST',
|
|
body: JSON.stringify({
|
|
email
|
|
})
|
|
}
|
|
|
|
fetch('/brevo-create-contact.json', options)
|
|
.then(res => res.json())
|
|
.then(json => {
|
|
console.log(json)
|
|
this.$refs.emailInput.value = 'Vous êtes inscrit !'
|
|
this.$refs.emailSubmit.setAttribute('disabled', 'true')
|
|
})
|
|
} else {
|
|
this.btnMsg = 'email invalide'
|
|
this.$refs.emailInput.value = ''
|
|
setTimeout(() => {
|
|
this.btnMsg = 'réessayer'
|
|
}, 2000)
|
|
}
|
|
}
|
|
}"
|
|
class="grid"
|
|
>
|
|
<p class="grid__item" style="--span: 6;">Inscrivez-vous à notre newsletter pour être tenue informé·e·s de nos dernières actualités !</p>
|
|
<form class="grid__item" action="" style="--span: 6;">
|
|
<input placeholder="e-mail" type="email" name="email" autocomplete="email" id="email" x-ref="emailInput">
|
|
<button type="submit" @click="submit" x-text="btnMsg" x-ref="emailSubmit"></button>
|
|
</form>
|
|
</div>
|
|
</section> |