Form previewSubmissions stay in this preview

Use this template

The first step validates scores from zero through ten. A back button lets respondents update the score without losing their comment.

Copy the code

Replace the example origin and access key with the values from your form’s setup screen. Send a test message from each site you publish and check the submission in your inbox.

HTML
<form id="survey" action="https://api.bitebrake.com/api/submit" method="post">
  <input type="hidden" name="access_key" value="YOUR_FORM_ACCESS_KEY">
  <fieldset>
    <legend>Step 1 of 2</legend>
    <label>How likely are you to recommend us? <input name="score" type="number" min="0" max="10" required></label>
    <button type="button" data-step="1" hidden>Continue</button>
  </fieldset>
  <fieldset>
    <legend>Step 2 of 2</legend>
    <label>What influenced your score? <textarea name="reason" rows="4"></textarea></label>
    <button type="button" data-step="-1" hidden>Back</button>
    <button type="submit">Send feedback</button>
  </fieldset>
  <div hidden><label>Leave empty <input name="botcheck" tabindex="-1" autocomplete="off"></label></div>
</form>

<script type="module">
  const form = document.querySelector("#survey");
  const steps = [...form.querySelectorAll("fieldset")];
  let current = 0;

  function showStep(index, focus = true) {
    current = index;
    steps.forEach((step, position) => { step.hidden = position !== current; });
    steps[1].disabled = current === 0;
    if (focus) steps[current].querySelector("input, textarea, select, button")?.focus();
  }

  form.querySelectorAll("[data-step]").forEach((button) => { button.hidden = false; });
  showStep(0, false);

  form.addEventListener("click", (event) => {
    const next = event.target.closest("[data-step]");
    if (!next) return;
    const direction = Number(next.dataset.step);
    if (direction > 0) {
      const invalid = steps[current].querySelector(":invalid");
      if (invalid && !invalid.reportValidity()) return;
    }
    showStep(current + direction);
  });

  form.addEventListener("keydown", (event) => {
    if (current !== 0 || event.key !== "Enter" || !event.target.matches("input")) return;
    event.preventDefault();
    steps[0].querySelector('[data-step="1"]').click();
  });
</script>
Connect this templateBrowse form templates