I was so shocked that some servers have a problem regarding the Submit Type Name and gives a "Not Acceptable error" or Error 406.
Consider the example below :
<form action="blah.php" method="POST">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submit_btn" id="Submit_btn" value="Send">
</td>
</tr>
</table>
</form>
This very simple code triggers the "Not Acceptable Error" on
PHP Version 5.2.5 and Apache 1.3.41 (Unix) Server.
However to fix this below is the right code:
<form action="blah.php" method="POST">
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="Submitbtn" id="Submit_btn" value="Send">
</td>
</tr>
</table>
</form>
The only problem that took me hours to find out is the "_" in the Submit Button.
Hope this help!
폼 다루기
PHP의 매우 강력한 기능의 하나는 HTML 폼을 다루는 방법입니다. 이를 이해하는데에 중요한 기본적인 컨셉은 어떤 폼 요소라도 자동적으로 PHP 스크립트에서 사용 가능하다는 점입니다. PHP로 폼을 이용하는 많은 정보와 예제를 위해서 매뉴얼의 PHP 외부에서 들어오는 변수 섹션을 읽어보십시오. 다음은 HTML 폼의 예제입니다:
Example#1 간단한 HTML 폼
<form action="action.php" method="post"> <p>이름: <input type="text" name="name" /></p> <p>연령: <input type="text" name="age" /></p> <p><input type="submit" /></p> </form>
이 폼에는 특별한 것은 아무것도 없습니다. 어떠한 특별한 태그도 가지지 않는 단순한 HTML 폼입니다. 유저가 이 폼을 채우고 submit 버튼을 누르면, action.php 페이지가 호출됩니다. 이 파일은 다음처럼 작성할 수 있습니다:
Example#2 폼으로부터의 데이터 출력하기
<?php echo $_POST['name']; ?>씨 안녕하세요.
당신은 <?php echo $_POST['age']; ?>세입니다.
이 스크립트의 출력 예제:
Joe씨 안녕하세요. 당신은 22세입니다.
이것이 무엇을 하는지는 명백합니다. 더 이상 할 일은 없습니다. $_POST['name']와 $_POST['age'] 변수는 PHP가 자동적으로 사용할수 있도록 설정합니다. 위에서 자동전역 $_SERVER를 사용했듯이, 이번에는 모든 POST 데이터를 포함하는 $_POST 자동전역을 소개합니다. 폼에서 method를 POST로 설정한 점에 주의하십시오. 폼에서 GET method로 지정하면, 폼 정보는 $_GET 자동전역이 포함합니다. 요청한 데이터가 어떤 소스인지를 신경쓰지 않을 때는 $_REQUEST 자동전역을 사용할 수 있습니다. 이는 GET, POST, COOKIE 데이터를 포함합니다. import_request_variables() 함수를 참고하십시오.
한동안은 잘 지원되는 HTML 폼에 만족할 수도 있지만, PHP에서는 XForms 입력을 다룰 수도 있습니다. XForms로 작업하는 것은 초보자를 위한 것은 아니지만, 흥미를 가질 것입니다. 기능 섹션에서 XForms로 받은 데이터를 다루는 짧은 안내를 참고하십시오.
폼 다루기
29-Mar-2008 10:27
03-Jan-2008 06:38
One thing that tripped me up when I was first learning PHP was the use of the NAME attribute in form fields. The current convention is to use the ID attribute instead when creating forms. (Many HTML editors automatically include an ID attribute without a NAME attribute.) Now, I include both the NAME and ID attributes (with the same value) in all my form fields.
For example...
<form method="post">
<input type="text" id="field1">
<input type="submit" value="go">
</form>
If you then have a PHP page requesting the contents of the "field1" field...
<?php echo $_POST["field1"] ?>
...the above form will always return an empty string for "field1".
The solution is to include the NAME attribute...
<form method="post">
<input type="text" id="field1" name="field1">
<input type="submit" value="go">
</form>
With this change, the PHP code will correctly retrieve the value of the "field1" field.
08-Nov-2006 08:02
As Seth mentions, when a user clicks reload or goes back with the browser button, data sent to the server, may be sent again (after a click on the ok button).
It might be wise, to let the server handle whatever there is to handle, and then redirect (a redirect is not visible in the history and thus not reachable via reload or "back".
It cannot be used in this exact example, but as Seth also mentions, this example should be using GET instead of POST
05-May-2005 12:18
[Editor's Note: Since "." is not legal variable name PHP will translate the dot to underscore, i.e. "name.x" will become "name_x"]
Be careful, when using and processing forms which contains
<input type="image">
tag. Do not use in your scripts this elements attributes `name` and `value`, because MSIE and Opera do not send them to server.
Both are sending `name.x` and `name.y` coordiante variables to a server, so better use them.
01-Dec-2003 12:55
According to the HTTP specification, you should use the POST method when you're using the form to change the state of something on the server end. For example, if a page has a form to allow users to add their own comments, like this page here, the form should use POST. If you click "Reload" or "Refresh" on a page that you reached through a POST, it's almost always an error -- you shouldn't be posting the same comment twice -- which is why these pages aren't bookmarked or cached.
You should use the GET method when your form is, well, getting something off the server and not actually changing anything. For example, the form for a search engine should use GET, since searching a Web site should not be changing anything that the client might care about, and bookmarking or caching the results of a search-engine query is just as useful as bookmarking or caching a static HTML page.
