0

I am using this form on my php file to create the form

  <input type="text" name="OrderLNumber" id="OrderLNumber" >
  <br>
  <input type="submit" name="submit" value="Status">

</form>

after that I am trying to pre-fill the form OrderLNumber field from this URL:

status/2727?OrderLNumber=24206927

Page loads normally but field is not filled as I intend to. How can I make this work ?

  • Take a look at the answer here: https://stackoverflow.com/a/43980063/4925511 which makes use of the [URL constructor](https://developer.mozilla.org/en-US/docs/Web/API/URL/URL). – frontend_friend Dec 02 '18 at 01:14
  • My form is being created through my php template file so this method is not usable mate. – Symeon Laftsopoulos Dec 02 '18 at 01:27
  • The question is tagged with 'javascript', hence my suggestion. Do you have control over how the form is rendered? If so, you might be able to do something like this: `" ... />` which would pre-fill the value. – frontend_friend Dec 02 '18 at 01:40
  • I could do that but I want the user to be able to change the value. If I do it like this then the user will only have the option of using the pre-populated value. – Symeon Laftsopoulos Dec 02 '18 at 01:41
  • I'm not sure what you mean; the value would be pre-filled, but the user can still modify the value in the input field. Can you expand on your question a bit? – frontend_friend Dec 02 '18 at 01:43

1 Answers1

0

You need to get the order number from the url by using the $_GET['OrderLNumber'] variable.

The code below will test to see if the form has been submitted. If the from has loaded fresh with no POST data it will grab the order number from the url. If the form has been submitted and there is POST data it will use whatever is in the form for the order id.

Like so:

<?php

if(isset($_POST['OrderLNumber']) && $_POST['OrderLNumber']){

  $orderLNumber = $_POST['OrderLNumber'];

}else{

  if(isset($_GET['OrderLNumber']) && $_GET['OrderLNumber']){

  $orderLNumber = $_GET['OrderLNumber'];

  }

}

?>


<form action="" method="POST">

  <input type="text" name="OrderLNumber" id="OrderLNumber" value=" <?php echo $orderLNumber; ?> " ><br>
  <input type="submit" name="submit" value="Status">

</form>

Hope this helps.

Joseph_J
  • 3,654
  • 2
  • 13
  • 22