我在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)
我怎样才能让它去http://mysite.com/form?q=textUserEntered
or http://mysite.com/index.php/form?q=textUserEntered
同时仍然将表单数据传递给 form.php
我更喜欢使用 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 添加到 action 属性的值会使 URLhttp://mysite.com/form.php?q=userEnteredText
not http://mysite.com/form?q=userEnteredText
只需告诉表单将数据发送到哪里,不需要重定向:
<form method="get" action="form.php">
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)