來自

http://www.thefutureoftheweb.com/blog/use-empty-form-action-submit-to-current

 

 

The title says it all: you can use an empty action attribute on a form to submit that form to the current page. This means you don't need to use server-side scripting (using REQUEST_URI or PHP_SELF or whatnot) to write the current URL into the HTML.

The following is perfectly valid:

<form action="" method="post">
<p><input type="submit"/></p>
</form>

Now beware, the action attribute is mandatory, and it must contain a valid URI. But according to the URI RFC, an empty URI is still a URI:

4.2. Same-document References

A URI reference that does not contain a URI is a reference to the current document. In other words, an empty URI reference within a document is interpreted as a reference to the start of that document, and a reference containing only a fragment identifier is a reference to the identified fragment of that document. Traversal of such a reference should not result in an additional retrieval action. However, if the URI reference occurs in a context that is always intended to result in a new request, as in the case of HTML's FORM element, then an empty URI reference represents the base URI of the current document and should be replaced by that URI when transformed into a request.

So there you have it. Enjoy.

創作者介紹
創作者 aftcast 的頭像
aftcast

蕭沖的書房

aftcast 發表在 痞客邦 留言(8) 人氣()


留言列表 (8)

發表留言
  • GrandRURU
  • 看了很久才發現……原來它跟BCB沒有關係!哈!
  • Alastair
  • 第一忠誠,第二勤奮,第三專心工作。
  • Angel
  • All good things come to an end.
  • 小小婦人
  • keep sharing with us, please....I will waiting your up date everyday!! Have a nice and relax day!
  • GIGI
  • 每次看完你的文章,總是回味許久,要經常發表喔。
  • 蘿拉
  • 甘巴嗲!祝你愈來愈好!
  • 紫楓
  • 祝福您春風得意。
  • lban
  • 果然很有意思呀....這當然要頂一頂呀 ̄﹏ ̄