1

Please refer to the following code:

<cfform method="POST" action="#CGI.script_name#">
    <p>Enter your Name:&nbsp;
    <input name="name" type="text" hspace="30" maxlength="30">
    <input type="Submit" name="submit" value="OK">
</cfform>
<cfscript>
    function HelloFriend(Name) {
        if (Name is "") WriteOutput("You forgot your name!");
        else WriteOutput("Hello " & name &"!");
        return "";
    }
    if (IsDefined("Form.submit")) HelloFriend(Form.name);
</cfscript>

Source: http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=UDFs_01.html#1167055

The code runs fine even without CGI.script_name attribute of action field. May I know why it's required then? The description says "Uses the script_name CGI variable to post to this page without specifying a URL. "

4

1 回答 1

3

当指定 no 时,HTML 表单的默认操作是提交给自己action。请参阅有关该主题的相关讨论:将空 URL 用于 HTML 表单的操作属性是一种好习惯吗?(动作="")

如果没有其他原因,我总是包括一个action,以避免混淆。

于 2013-06-28T12:52:14.490 回答