Formulaire

Garder les paramètres d’URL après une soumission de formulaire

<script>

document.querySelector('[js-queryparam-element=form]').addEventListener('submit', function (e) {
  e.preventDefault();

  const inputFields = document.querySelectorAll('input[js-queryparam-name]');

  const utmParams = {};

  for (const inputField of inputFields) {
    const utm_element = inputField.getAttribute('js-queryparam-name');
    const { value } = inputField;
    utmParams[utm_element] = value;
  }

  const pageURL = document.querySelector('[js-queryparam-slug]').getAttribute('js-queryparam-slug');
  const queryParams = new URLSearchParams(utmParams).toString();
  const fullUrl = pageURL + '?' + queryParams;

  window.location.href = fullUrl;
});
</script>

Etape 1 - Ajouter le script sur la page ou le projet Webflow

<!-- Scripts by Justa | Keep Query Params After Submission -->
<script src="https://cdn.jsdelivr.net/npm/@justaa/scripts/dist/forms/keep-query-params.js"></script>
<script>

document.querySelector('[js-queryparam-element=form]').addEventListener('submit', function (e) {
  e.preventDefault();

  const inputFields = document.querySelectorAll('input[js-queryparam-name]');

  const utmParams = {};

  for (const inputField of inputFields) {
    const utm_element = inputField.getAttribute('js-queryparam-name');
    const { value } = inputField;
    utmParams[utm_element] = value;
  }

  const pageURL = document.querySelector('[js-queryparam-slug]').getAttribute('js-queryparam-slug');
  const queryParams = new URLSearchParams(utmParams).toString();
  const fullUrl = pageURL + '?' + queryParams;

  window.location.href = fullUrl;
});
</script>
Copier

Etape 2 - Ajouter les attributes correspondants

Form - Identifier l'élément Formulaire

Input - Identifier chaque input récupérant un paramètre d'URL

Form - Identifier le slug de direction

Tuto, template & scripts

<script>

document.querySelector('[js-queryparam-element=form]').addEventListener('submit', function (e) {
  e.preventDefault();

  const inputFields = document.querySelectorAll('input[js-queryparam-name]');

  const utmParams = {};

  for (const inputField of inputFields) {
    const utm_element = inputField.getAttribute('js-queryparam-name');
    const { value } = inputField;
    utmParams[utm_element] = value;
  }

  const pageURL = document.querySelector('[js-queryparam-slug]').getAttribute('js-queryparam-slug');
  const queryParams = new URLSearchParams(utmParams).toString();
  const fullUrl = pageURL + '?' + queryParams;

  window.location.href = fullUrl;
});
</script>
Copier

Etape 2 - Ajuster le code pour votre besoin

Copié dans le presse-papiers
Logo Justa

Progressez sur Webflow

Oops! Une erreur s'est produite lors de la soumission du formulaire.