submit html form on self page

2019-01-21 21:10发布

I want html form submit on self page, how to use 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条回答
爷的心禁止访问
2楼-- · 2019-01-21 21:37

Use ? ,

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

it will help you to stay on the same page

查看更多
何必那么认真
3楼-- · 2019-01-21 21:44

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

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

for security.

查看更多
相关推荐>>
4楼-- · 2019-01-21 21:45

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

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

查看更多
神经病院院长
5楼-- · 2019-01-21 21:46

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

<form action="">

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.

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.

So they both still valid and works:

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

UPDATE #2

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

<form>
查看更多
够拽才男人
6楼-- · 2019-01-21 21:57

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

查看更多
劳资没心,怎么记你
7楼-- · 2019-01-21 21:59

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

<form>

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

From this other Stackoverflow answer

查看更多
登录 后发表回答