简体   繁体   中英

Can the action attribute on a form element be empty?

As of HTML5, the widely used and recommended action="" is invalid HTML.

From the specs:

The action and formaction content attributes, if specified, must have a value that is a valid URL.

So what is the correct way to have the action attribute point to the current page?

I am currently using

action="<php htmlspecialchars($_SERVER["REQUEST_URI"]); ?>"

It's true that the action= attribute may not be empty, as an empty string is not a valid URL. However, it is valid to simply leave it out, and let the browser figure it out.

The browser will assume the current page.

You can set value to '.' or do not set action attribute at all.

<form method="post">
or
<form method="post" action=".">

(I was surprise but it is really invalid to leave it blank, at least validator.w3.org is returning error).

不可以,在HTML5中,可以省略action属性 ,它默认为emoty字符串,表示对当前文档的引用。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM