0

so I have a a PHP Form handler that I have a hidden field in. I use this all the time in my header, however, I have not used it inside a php file. I access the jquery library, use $(document).ready(function () and have my variables inside, as well as getURLParameter("tid"), then ($tbody).html $("tbody").html($("tbody").html().replace(/{{transaction_id}}/g,replaceString));

I keep getting the error: Uncaught ReferenceError: getURLParameter is not defined

I'm probably missing something here, as I have not done this inside a PHP file before.

Should I use .php instead of .html?

Here is the snippet of code:

<?php } ?>
    <table width="250"><tbody>
        <script src="https://code.jquery.com/jquery-3.4.1.js"></script>
<script>
$(document).ready(function () {
    var replaceString = "NO TID";
    var urlTerm = getURLParameter("tid");
    if (urlTerm.trim().length > 0 && urlTerm != "null") {
        replaceString = decodeURIComponent(urlTerm).replace(/\+/g,' ');
    }
    $("input.transaction_id").html($("input.transaction_id").html().replace(/\{\{transaction_id\}\}/g,replaceString));
});
</script>
<tr><td><form id="signupform" class="signup_form" action="/testing-kirby.php" method="post"><div><div><input  class="signup-name-area" style="height: 32px; width: 325px;" name="name" type="text" placeholder="Full Name"><br><br><input class="signup-email-area" style="height: 32px; width: 325px;" name="email" required="required" type="email" placeholder="email@example.com"><div style=" margin-top: 15px;"<center><input class="signup-button-2" style="background-color: red; height: 48px;" type="submit" value="Sign Petition"></center></div><input name="loc" type="hidden" value="header"></div></div><input name="tid" class="transaction_id" type="hidden" value="{{transaction_id}}"></div></form><p style="text-align: center;">Sponsored by:</p><p style="text-align:center;"><img src="https://wolfdaily.com/wp-content/uploads/2020/05/Wolf-Daily-Final-160h.png" width="200"></p></td></tr></tbody></table>

Thank you!

  • You need to define the function getURLParameter somewhere in your code or you forgot to import it. Check solution here https://stackoverflow.com/questions/19491336/how-to-get-url-parameter-using-jquery-or-plain-javascript – themhz Oct 18 '21 at 21:17

1 Answers1

0

You don't need to replace it with jQuery. If its php you can get the url parameter like

var urlTerm = "<?php echo $_GET["tid"] ?>";

However if you still wana do it with JavaScript consider the solution here because you need to define the function getURLParameter somewhere in your code or you forgot to import it.

themhz
  • 8,335
  • 21
  • 84
  • 109
  • That makes more sense. Can I place echo $_GET["tid"] directly into a redirect url? Or will I need to get it, then set it as a global variable? Not sure how I'm going to place it in my redirect URL as I'm a bit rusty. – KirbyBell561 Oct 19 '21 at 22:30
  • Here is what I'm trying right now: $tid = $_GET['tid']; declaring it as a variable. Then placing that variable in my url redirect string. Would that work? Think I'm missing something. Also, should I make it a global variable in my function? Thank you! – KirbyBell561 Oct 19 '21 at 22:40
  • if the file is .php extension then you can place anyware in the file any php code, as long as you keep the php tags – themhz Oct 20 '21 at 12:01
  • PHP $_GET is a PHP super global variable which is used to collect form data after submitting an HTML form with method="get". $_GET can also collect data sent in the URL. – themhz Oct 20 '21 at 12:02