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. "

Miguel-F
  • 13,450
  • 6
  • 38
  • 63
Tan
  • 1,433
  • 5
  • 27
  • 47

1 Answers1

4

The default action of an HTML form is to submit to itself when no action is specified. See this related discussion on the topic: Is it a good practice to use an empty URL for a HTML form's action attribute? (action="")

I always include an action, if for no other reason, to avoid confusion.

Community
  • 1
  • 1
Miguel-F
  • 13,450
  • 6
  • 38
  • 63