Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

138
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!