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

139
Visualizações
Try to generate a post method javascript links

I built a JAVASCRIPT into a PHP file that creates links to create links with the POST method, unfortunately it doesn't work, what am I doing wrong? which quotation marks should I choose in javascript?

echo '<form name="' . $i . '" method="post" action="?q=' . $query . '"><button type="submit" class="button" name="' . $i . '" value="' . $i . '">' . $i . '</button></form>';
echo '<script>
var button = document.querySelector(`form[name="` . $i .`"] > button`);
button.addEventListener(function() {
  document.querySelector("form[name="` . $i .`"]").submit();
});
</script>';
}
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You can use \' (backlash followed by ').

See this link where I tested it: https://onlinegdb.com/FF_Um4YdS

<?php

// random data for test
$i = "random-form";
$query = "nothing";


echo '<form name="' . $i . '" method="post" action="?q=' . $query . '"><button type="submit" class="button" name="' . $i . '" value="' . $i . '">' . $i . '</button></form>';
echo '
<script>
    var formButton = "form[name=\''. $i .'\'] > button";
    var button = document.querySelector(formButton);
    button.addEventListener(function() {
        document.querySelector("form[name=\'' . $i .'\']").submit();
    });
    </script>';

?>
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