Skip to content
Advertisement

Track delivery status of DHL via form

I have a question. I have the following PHP script

<?php
$dhlsendnumber=$_GET['dhlsendnumber'];
{
   $uri="https://www.dhl.de/de/privatkunden/dhl-sendungsverfolgung.html?piececode=$dhlsendenummer";
   
   header("location: $uri");
   
   Exit;
}
?>

This allows me to check the status of a delivery number from DHL using a form with the following PHP.

    <?php
// basic form saved under the name: dhlsendeverfolgung.php
?>

<form action="dhlsendeverfolgung.php" method="get">

<p>Enter your DHL shipment number<br>.
<input type="Text" name="dhlsendenummer"></p>

<input type="Submit" name="" value="Request shipment status of your DHL package">

</form>

Maybe there is a better way to do this, but this works so far.

But this only works if I put the dhlsendeverfolgung.php in the root directory.

But I would like to be able to track a delivery number from a subpage of my website like https://samplepage/dhl-tracken using the form with the above code. But I don’t know in which folder I have to put the php file to achieve this or whatelse I have to do so that the link is found like when I have the form on the home page and in the root the php file.

Can someone help me to achieve this?

Furthermore, I would like to achieve that the DHL web page with the query opens in a new window and does not open in the same,

What do I need to do?

Would appreciate help

Advertisement

Answer

You could actually simplify this alot and do away with the other page entirely using javascript:

function sendToDHL(form) {
  let num = form.querySelector('input[name="dhlsendenummer"]').value.trim();
  if (!num) {
    alert("Please input a tracking number");
    return;
  }
  let url = "https://www.dhl.de/de/privatkunden/dhl-sendungsverfolgung.html?piececode=" + num;
  window.open(url, 'DHLTracking');
}
<form onsubmit="sendToDHL(this); return false;">
  <p>Enter your DHL shipment number.<br>
    <input type="text" name="dhlsendenummer"></p>
  <input type="submit" name="" value="Request shipment status of your DHL package">
</form>
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement