I have a form at index.php that takes in user input, it the includes and sends the user input to another php file for processing.
Here is the code of index.php:
<?php
if(isset($_GET['q'])){
include_once "form.php";
exit(0);
}
?>
<!Doctype HTML>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Search</title>
</head>
<body>
<form method="get">
<input type="text" name="q" />
</form>
</body>
</html>
When one submits the form it goes to http://mysite.com/?q=textUserEntered (if just the domain was visited before) or http://mysite.com/index.php?q=textUserEntered (if index.php is visited before)
How can I get it to go to http://mysite.com/form?q=textUserEntered or http://mysite.com/index.php/form?q=textUserEntered while still passing the form data to form.php
I tried this in the beginning index.php and form.php, it navigates to the URL but doesn’t pass the data to form.php and instead goes to a 404 error page.
if(!empty($_GET['q']))
{
header("Location: form?q=".rawurlencode($_GET['q']));
exit;
}
Update:
I can’t use the action attribute because adding form.php to the value of the action attribute would make the URL http://mysite.com/form.php?q=userEnteredText not http://mysite.com/form?q=userEnteredText