php – How to redirect to a specific URL baed on the data submitted?-ThrowExceptions

Exception or error:

I am trying to create a form which, when submitted, redirects the user to a specific URL which contains the content of the submission at the end of the URL.

So, for example, a simple form like this:

<form method="post">
    <input type="text" name="tracking">
    <input type="submit" name="submit" value="submit">

When the user types “abc” as the tracking number and clicks ‘submit’ they would be redirected to:

My question is, is this possible and if so, how can it be done?

This is what I have so far…

On the form page:

<form action="redirect_form.php" id="#form" method="post" name="#form">
<label>Enter your tracking code:</label>
<input id="tracking" name="tracking" placeholder='Enter your tracking code' type='text'>
<input id='btn' name="submit" type='submit' value='Submit'>
<?php include "include/redirect.php"; ?>

included in the redirect.php file:

// Fetching variables of the form which travels in URL
$name = $_POST['tracking'];
//  To redirect form on a particular page
?><span><?php echo "Please enter tracking number.";?></span> <?php
How to solve:

Probably JavaScript will be enough here:

<input type="text" id="tracking" name="tracking">
<input type="button" name="submit" value="submit" onclick="window.location.replace(''+tracking.value);">


you should use the GET method for this.
With javascript you can then extract the text input and manipulate the url to which the user is redirected to.
Hope that helps you further.

Leave a Reply

Your email address will not be published. Required fields are marked *