窗体未使用正在操作的文件属性


Form not using the file in action attribute

我有一个非常简单的HTML表单它应该通过GET将信息发送到文件写入操作属性但不知怎么它将信息传输回index。php:

index . php

<!doctype html>
<html>
<head>
    <title>Sandbox</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>PHP Forms Sandbox</h1>
<form acton="process_form.php" method="get">
    <label for="username">Username:</label>
    <input type="text" name="username" id="username" value="" />
    <label for="email">E-mail:</label>
    <input type="text" name="email" id="email" value="" />
    <input type="submit" name="submit_btn" id="submit_btn" value="Submit" />
</form>
</body>
</html>

process_form.php

<!doctype html>
<html>
<head>
    <title>Sandbox</title>
    <meta charset="utf-8" />
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>PHP Response Sandbox</h1>
<?php
$username = $_GET["username"];
$email = $_GET["email"];
echo $username . " : " . $email . "<br />";
?>
</body>
</html>
奇怪的是,当我提交表单时,URL显示它甚至没有使用process_form.php:
http://127.0.0.1/Learning/?username=test&email=x%40test.com&submit_btn=Submit

如果我手动更改URL以包括process_form.php它似乎工作得很好,我得到我正在寻找的结果:

http://127.0.0.1/Learning/process_form.php?username=test&email=x%40test.com&submit_btn=Submit

在我的开发计算机上,我正在运行EasyPHP 14.1本地WAMP服务器,并认为这可能是问题的根源,所以我将文件上传到我的网站,在Apache上运行最新的PHP,但问题仍然存在。

我做错了什么?

你在action中有一个打字错误;您已经给了 action 。应该是这样的:

<form action="process_form.php" method="get">

第一件事-你有一个打字错误:

<form action="process_form.php" method="get">
         ^

第二件事-在我看来,处理表单的最佳方法是使用POST方法,而不是GET,所以我将其更改为:

<form action="process_form.php" method="post">

process_form.php中,我将使用$_POST而不是$_GET

在深入研究了你的问题之后,

index . php

<!doctype html>
<html>
<head>
<title>Sandbox</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>
<h1>PHP Forms Sandbox</h1>
<form action="process_form.php" method="get">
<label for="username">Username:</label>
<input type="text" name="username" id="username" value="" />
<label for="email">E-mail:</label>
<input type="text" name="email" id="email" value="" />
<input type="submit" name="submit_btn" id="submit_btn" value="Submit" />
</form>
</body>
</html>

process_form.php

<!doctype html>
<html>
<head>
<title>Sandbox</title>
<meta charset="utf-8" />
<link rel="stylesheet" type="text/css" href="style.css">
</head>
<body> 
<h1>PHP Response Sandbox</h1>
<?php
$username = $_GET["username"];
$email = $_GET["email"];
echo $username . " : " . $email . "<br />";
?>
</body>
</html>

注意:如果你不指定表单方法,默认使用GET方法。所以请确保动作应该是完美的。

上面的代码只是复制粘贴,它应该工作完美。

请让我进一步说明。

谢谢,Gauttam