提交html表单在self页面。

时间:2022-11-23 13:24:02

I want html form submit on self page, how to use action atribute

我想在自己的页面上提交html表单,如何使用action atribute

<form action="">

or

<form action="#">

or

<form action="here write addres this page">

or just simple not use action atribute ?

或者只是简单的不使用动作心房纤颤?

what is much better way ?

什么是更好的方法?

6 个解决方案

#1


91  

In 2013, with all html5 stuff, you can just ommit the 'action' attribute to self-submit a form

在2013年,有了所有html5的东西,你就可以省略“action”属性来自动提交表单

<form>

Actually, the Form Submission subsection of the current HTML5 draft does not allow action="" (empty attribute). It is against the spec.

实际上,当前HTML5草案的表单提交小节不允许action=“(空属性)”。这是违反规格的。

From this other * answer

从这个*回答

#2


9  

If you are submitting a form using php be sure to use:

如果您正在使用php提交表单,请务必使用:

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

for security.

为安全。

#3


7  

You can leave action attribute blank. The form will automatically submit itself in the same page.

可以将action属性留空。表单将自动提交到相同的页面中。

<form action="">

UPDATE #1

UPDATE # 1

According to the w3c specification, action attribute must be non-empty valid url in general. There is also an explanation for some situations that action attribute may be leave empty.

根据w3c规范,操作属性通常必须是非空有效url。在某些情况下,还可以对操作属性可能是空的情况进行解释。

The action of an element is the value of the element’s formaction attribute, if the element is a Submit Button and has such an attribute, or the value of its form owner’s action attribute, if it has one, or else the empty string.

元素的动作是元素的formaction属性的值(如果元素是提交按钮并具有这样的属性),或者是其窗体所有者的动作属性的值(如果有),或者是空字符串。

So they both still valid and works:

所以它们仍然有效

<form action="">
<form action="FULL_URL_STRING_OF_CURRENT_PAGE">

UPDATE #2

更新# 2

If you are sure about your audience is using html5 browsers then you can even omit action attribute:

如果你确定你的用户正在使用html5浏览器,那么你甚至可以省略action属性:

<form>

#4


2  

Use ? ,

使用?,

 <form action="?" method="post">

it will help you to stay on the same page

这将帮助你保持一致

#5


1  

You can do it using the same page on the action attribute: action='<yourpage>'

可以在action属性上使用相同的页面:action=' '

#6


0  

try this same form action page url, it will direct the same page

尝试相同的表单操作页面url,它将指向相同的页面。

form action="/cgi-bin/html5.cgi" method="get"

表单动作= " /目录/ html5。cgi”方法= "得到"

#1


91  

In 2013, with all html5 stuff, you can just ommit the 'action' attribute to self-submit a form

在2013年,有了所有html5的东西,你就可以省略“action”属性来自动提交表单

<form>

Actually, the Form Submission subsection of the current HTML5 draft does not allow action="" (empty attribute). It is against the spec.

实际上,当前HTML5草案的表单提交小节不允许action=“(空属性)”。这是违反规格的。

From this other * answer

从这个*回答

#2


9  

If you are submitting a form using php be sure to use:

如果您正在使用php提交表单,请务必使用:

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

for security.

为安全。

#3


7  

You can leave action attribute blank. The form will automatically submit itself in the same page.

可以将action属性留空。表单将自动提交到相同的页面中。

<form action="">

UPDATE #1

UPDATE # 1

According to the w3c specification, action attribute must be non-empty valid url in general. There is also an explanation for some situations that action attribute may be leave empty.

根据w3c规范,操作属性通常必须是非空有效url。在某些情况下,还可以对操作属性可能是空的情况进行解释。

The action of an element is the value of the element’s formaction attribute, if the element is a Submit Button and has such an attribute, or the value of its form owner’s action attribute, if it has one, or else the empty string.

元素的动作是元素的formaction属性的值(如果元素是提交按钮并具有这样的属性),或者是其窗体所有者的动作属性的值(如果有),或者是空字符串。

So they both still valid and works:

所以它们仍然有效

<form action="">
<form action="FULL_URL_STRING_OF_CURRENT_PAGE">

UPDATE #2

更新# 2

If you are sure about your audience is using html5 browsers then you can even omit action attribute:

如果你确定你的用户正在使用html5浏览器,那么你甚至可以省略action属性:

<form>

#4


2  

Use ? ,

使用?,

 <form action="?" method="post">

it will help you to stay on the same page

这将帮助你保持一致

#5


1  

You can do it using the same page on the action attribute: action='<yourpage>'

可以在action属性上使用相同的页面:action=' '

#6


0  

try this same form action page url, it will direct the same page

尝试相同的表单操作页面url,它将指向相同的页面。

form action="/cgi-bin/html5.cgi" method="get"

表单动作= " /目录/ html5。cgi”方法= "得到"