Hi community 🙂

Today we’ll show you how you can use Palabra to send an automated email every time a user answers a Javascript form.

You can use this workflow when you need to automate an email after a users signs up, when a user cancels a subscription, or subscribes to a newsletter.
Follow the steps on this guide to connect your landing page or blog to Palabra.

The first step is to go to your Palabra dashboard and click on the plus sign on the left sidebar to create a new trigger:

Now that you have your new trigger created, you should add a condition that will trigger your emails (this will be your form connection).

To connect it, on the ‘When’ click on the ‘Add condition’ button.

On this new window, on the left sidebar click on ‘For developers’ and from there click on the card that says ‘Request came from webhook’:

Now you should have a new card on your board that indicates that there is some work to be done. Let’s click on that card to complete the connection:

On this card let’s start by copying the webhook URL. To copy it just click on it.

The next step is to go to your website. If you don’t have a form already here’s a simple one you can use:

  <h1>Your form</h1>
  <input type="text" name="email" id="email" />
  <button id="button">Sign up</button>
<script src="scripts.js"></script>

On your javascript file let’s handle what happens when the use clicks on the “Sign up” button.

To do that you can paste the following:

const $input = document.querySelector("#email");
const $button = document.querySelector("#button");

$button.addEventListener("click", async () => {
  const email = $input.value;

  await fetch("[YOUR-PALABRA-URL]", {
    method: "POST",
    headers: {
      "Content-Type": "application/x-www-form-urlencoded"
    body: `email=${email}`

Make sure you replace [YOUR-PALABRA-URL] with the URL you copied from Palabra (it will look something like: https://hooks.palabra.io/js/?id=[SOMETHING]).

Now that your code is ready, let’s go back to Palabra and click on the ‘Test connection’ button.

The final step is to submit the form on your website. When you do you’ll see the content on the form on Palabra, like this:

Now the connection with your website is ready the only thing that’s left is creating an email that will go out every time a user submits the form on your website.

To add an email click on the ‘Add task’ button.

On this window, select ‘Empty email’ on the left sidebar and the ‘Send an email’ card.

Back on your board, if you click the ‘Send an email’ card you’ll be able to edit the contents of the email.

After your are done editing the subject and contents of the email you can close the card and the changes will be saved.

Now that the connection with your website and emails are done you can turn this trigger on. To do that move the button on the top right from ‘Off’ to ‘On’.

And that’s it! Every time a user submits a form they’ll receive this email you just setup.