我正在尝试创建一个表单,该表单在提交时会将用户重定向到特定的 URL,该 URL 包含 URL 末尾的提交内容。
因此,例如,像这样的简单形式:
<form method="post">
<input type="text" name="tracking">
<input type="submit" name="submit" value="submit">
</form>
当用户键入“abc”作为跟踪号并单击“提交”时,他们将被重定向到:
https://www.specificurl.com/abc
我的问题是,这可能吗?如果可以,怎么做?
这是我目前所拥有的......
在表单页面上:
<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"; ?>
</form>
包含在 redirect.php 文件中:
<?php
if(isset($_POST['submit'])){
// Fetching variables of the form which travels in URL
$name = $_POST['tracking'];
if($tracking)
{
// To redirect form on a particular page
header("Location:https://specificurl.com/$tracking");
}
else{
?><span><?php echo "Please enter tracking number.";?></span> <?php
}
}
?>
白衣非少年
呼唤远方