Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

154
Visualizações
Submit form one time after page load via Jquery

How to submit the cart request-quote form after page load? Below code is worked fine -

<?php if(!isset($_GET['updated'])) { ?>
<script>
jQuery(document).ready(function($) {
jQuery("#yith-ywraq-form").submit();
});
</script>
<?php } ?>

But avoid submitting forms, again and again, I reload to this action site.com/request-quote/?updated=data

But if someone refreshes the same page site.com/request-quote/?updated=data then I have no option to submit the form again on page load.

do you have a solution for this problem?

My requirement is I want to submit the cart request-quote form 1 time after page load?

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

You may use localStorage for this. Take a flag in set some initial value of it. When the form submits update it's value. By checking the same you can avoid getting submit.

<?php if(!isset($_GET['updated'])) { ?>
    <script>
        if(!localStorage.getItem('isFormAlreadySubmit')){
            jQuery(document).ready(function($) {
                jQuery("#yith-ywraq-form").submit();
                localStorage.setItem('isFormAlreadySubmit', true);
            });
        }
    </script>
<?php } ?>
about 4 years ago · Juan Pablo Isaza Relatório

0

You can move $_GET['updated'] to localStorage or sessionStorage, then you don't need to reload the page to ?updated=data page anymore.

  • localStorage will save updated value even when the browser is closed and reopened.
  • sessionStorage will save updated value but it will be cleared if the browser is closed.

That depends on you to choose which one. So I make a demo with sessionStorage which I prefer because when the user closes the browser, it will clear the updated value, maybe the next user in that device is another (public device). I also remove the check if(!isset($_GET['updated'])) condition.

<script>
  jQuery(document).ready(function($) {
    if (!sessionStorage.getItem('updated')) {
      jQuery("#yith-ywraq-form").submit();
      sessionStorage.setItem('updated', true);
    }
  });
</script>

Update: add live demo https://codepen.io/tuandaodev/pen/jOwvrRg?editors=1111

about 4 years ago · Juan Pablo Isaza Relatório

0

You need to use a server side session variable to check (duplicate) Answer

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda