php 如果没有指定操作,表单提交到哪里?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5534300/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 21:44:25  来源:igfitidea点击:

Where does the form submit to if there is no action specified?

phpforms

提问by Matt Elhotiby

Here is the form that is confusing me

这是让我困惑的表格

<h1>
    Login
</h1>
<form action="" method="post">
    <table align="left" border="0" cellspacing="0" cellpadding="3">
        <tr>
            <td>
                Username:
            </td>
            <td>
                <input type="text" name="user" maxlength="30">
            </td>
        </tr>
        <tr>
            <td>
                Password:
            </td>
            <td>
                <input type="password" name="pass" maxlength="30">
            </td>
        </tr>
        <tr>
            <td colspan="2" align="left">
                <input type="checkbox" name="remember">
                <font size="2">
                    Remember me next time
            </td>
        </tr>
        <tr>
            <td colspan="2" align="right">
                <input type="submit" name="sublogin" value="Login">
            </td>
        </tr>
        <tr>
            <td colspan="2" align="left">
                <a href="register.php">Join</a>
            </td>
        </tr>
    </table>
</form>

I got the code from this tutorialand it works fine but i cant seem to understand where a/the form submit too if no action is present

我从本教程中获得了代码,它工作正常,但如果不存在任何操作,我似乎无法理解表单提交的位置

回答by Jimmy Sawczuk

If actionis set to ""or if the actionattribute is missing, the form submits to itself. That is, if your script is index.php, your form submits to index.php.

如果action设置为""action属性缺失,则表单提交给自身。也就是说,如果您的脚本是index.php,则您的表单提交到index.php.

回答by Old McStopher

If the form's action attribute is either set to ""ORnot specified, it will still default to action="self", thus the form will send to the address of the document containing the form.

如果表单的 action 属性设置为""OR未指定,它仍将默认为action="self",因此表单将发送到包含该表单的文档的地址。

So,

所以,

<form method="post">

<!-- IS THE SAME AS... -->

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

<!-- IS THE SAME AS... -->

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

(Try it)

(尝试一下)

For reference, see the HTML standard 4.10.18.3 #8:

作为参考,请参阅 HTML 标准 4.10.18.3 #8:

http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#form-submission-algorithm

http://www.whatwg.org/specs/web-apps/current-work/multipage/association-of-controls-and-forms.html#form-submission-algorithm

回答by Sourav

default action for form submission is METHOD="GET" and ACTION="SELF"
you should use a form name

表单提交的默认操作是 METHOD="GET" 和 ACTION="SELF"
您应该使用表单名称

if the action is empty then it posts to itself.

如果动作是空的,那么它会发布给自己。