ユーザー入力を取り込む index.php のフォームがあります。これには、ユーザー入力が含まれており、処理のために別の php ファイルに送信されます。
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>
フォームを送信すると、テキスト入力がフォーカスされているときに Enter キーを押すと、
http://mysite.com/?q=textUserEntered
(ドメインだけが以前にアクセスされた
http://mysite.com/index.php?q=textUserEntered
場合) または (index.php が以前にアクセスされた場合)
フォームデータを form.php に渡しながら、http://mysite.com/form?q=textUserEntered
またはフォームデータを渡すにはどうすればよいですかhttp://mysite.com/index.php/form?q=textUserEntered
PHP を使用したソリューションを希望しますが、これを行う唯一の方法が .htacess である場合は、共有してください。
最初の index.php と form.php でこれを試しました。URL に移動しますが、データを form.php に渡さず、404 エラー ページに移動します。
if(!empty($_GET['q']))
{
header("Location: form?q=".rawurlencode($_GET['q']));
exit;
}
action 属性の値に form.php を追加すると URL が無効になるため、action 属性は使用できませhttp://mysite.com/form.php?q=userEnteredText
ん。http://mysite.com/form?q=userEnteredText