# Is there a point specifying an action for HTML forms?

**URL:** https://boards.straightdope.com/t/is-there-a-point-specifying-an-action-for-html-forms/497222
**Category:** Factual Questions
**Created:** [May 21, 2009, 7:13pm UTC](https://boards.straightdope.com/t/is-there-a-point-specifying-an-action-for-html-forms/497222 "2009-05-21T19:13:13Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Lobsang](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/lobsang/32/4067_2.png) [@Lobsang](https://boards.straightdope.com/u/Lobsang)
#### Post date: [May 21, 2009, 7:13pm UTC](https://boards.straightdope.com/t/is-there-a-point-specifying-an-action-for-html-forms/497222/1 "2009-05-21T19:13:13Z")

</div>

Take PHP to be specific. I get this from my PHP textbook…

\<form action="\<?=$\_SERVER[‘PHP\_SELF’]?\>" method=“POST”\>  
But the PHP\_SELF bit is redundant. This…

\<form action="" method=“POST”\>

Does the same.

So is there a good reason to specifically point the page at itself, when that is the default?

---

<div class="post-metadata">

### Author: ![Cornelius\_Tuggerson](https://avatars.discourse-cdn.com/v4/letter/c/13edae/32.png) [@Cornelius\_Tuggerson](https://boards.straightdope.com/u/Cornelius_Tuggerson)
#### Post date: [May 21, 2009, 8:36pm UTC](https://boards.straightdope.com/t/is-there-a-point-specifying-an-action-for-html-forms/497222/2 "2009-05-21T20:36:16Z")

</div>

Never written a line of PHP in my life, but maybe action="" doesn’t work in all browsers or some such?

---

<div class="post-metadata">

### Author: ![UncleRojelio](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/unclerojelio/32/3160_2.png) [@UncleRojelio](https://boards.straightdope.com/u/UncleRojelio)
#### Post date: [May 21, 2009, 8:52pm UTC](https://boards.straightdope.com/t/is-there-a-point-specifying-an-action-for-html-forms/497222/3 "2009-05-21T20:52:03Z")

</div>

The bit between the quotes explicitly passes the filename to the action. If you want the action to call a different file you would put that filename instead.

---

<div class="post-metadata">

### Author: ![Terminus\_Est](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/terminus_est/32/3087_2.png) [@Terminus\_Est](https://boards.straightdope.com/u/Terminus_Est)
#### Post date: [May 21, 2009, 9:26pm UTC](https://boards.straightdope.com/t/is-there-a-point-specifying-an-action-for-html-forms/497222/4 "2009-05-21T21:26:43Z")

</div>

It is, apparently, unnecessary with PHP as it’s understood that PHP itself will process the data. However, in plain old HTML “action” is a required parameter that gives the URL of the application that will process the form’s data. This application is separate from the web server, by convention stored in a cgi-bin directory. The form tag would typically look like:

```auto

<form action="http://www.example.com/cgi-bin/process">
...
</form>

```

If you then go into the www-root directory, under ./cgi-bin/, you find find an executable file with the name of “process” that does the actual dirty work of processing the form data.

---

<div class="post-metadata">

### Author: ![LilShieste](https://avatars.discourse-cdn.com/v4/letter/l/9f8e36/32.png) [@LilShieste](https://boards.straightdope.com/u/LilShieste)
#### Post date: [May 21, 2009, 9:40pm UTC](https://boards.straightdope.com/t/is-there-a-point-specifying-an-action-for-html-forms/497222/5 "2009-05-21T21:40:20Z")

</div>

> [@Lobsang](#):
>
> So is there a good reason to specifically point the page at itself, when that is the default?

The HTML standard [requires the presence of this attribute](http://www.w3.org/TR/html401/interact/forms.html#adef-action). As such, if the attribute isn’t included within the \<form\> element, then it’s basically up to the individual browsers to decide how they want to handle it.

So, I would bet that PHP is explicitly designating the current page as the action handler so that:  
[ul]  
[li] Browsers that are sticklers for standard compliant HTML don’t freak out; **OR** [/li][li] Browsers don’t decide to use some arbitrary action handler (i.e., there’s nothing in the standard that explicitly states that a blank action handler should represent the current URI)[/li][/ul]

---

<div class="post-metadata">

### Author: ![Terminus\_Est](https://sea3.discourse-cdn.com/straightdope/user_avatar/boards.straightdope.com/terminus_est/32/3087_2.png) [@Terminus\_Est](https://boards.straightdope.com/u/Terminus_Est)
#### Post date: [May 21, 2009, 9:49pm UTC](https://boards.straightdope.com/t/is-there-a-point-specifying-an-action-for-html-forms/497222/6 "2009-05-21T21:49:59Z")

</div>

Ah, yes, the specs say that user behavior for a missing “action” parameter is undefined. So it’s not that PHP has a reasonable default but rather the browser had a reasonable default in passing the name of the self-URI, which so happened to be the script that processed the data from the form. Some other browsers may not be so forgiving.

---

<div class="post-metadata">

### Author: ![wasson](https://avatars.discourse-cdn.com/v4/letter/w/4da419/32.png) [@wasson](https://boards.straightdope.com/u/wasson)
#### Post date: [May 22, 2009, 12:36am UTC](https://boards.straightdope.com/t/is-there-a-point-specifying-an-action-for-html-forms/497222/7 "2009-05-22T00:36:54Z")

</div>

The method is quite necessary and getting more so, in PHP at least.

Forms, depending on the browser, default to the “get” method rather than “post”, which means form information is thrown into the URL in a long string (?var1=whatever&var2=whateverelse).

On the PHP page which retrieves this input, it is retrieved using “$\_GET[‘var1’]”.

If the form method is specified as “post”, the PHP will retrieve the form input as “$\_POST[‘var1’]”. In this case the form inputs are NOT in the url.

In previous versions of PHP, \_GET and \_POST variables are treated equally, if global\_registers is on. Similarly, you can use $\_REQUEST to get the input from either get or post.

However, because of security concerns, this is changing in the latest version of PHP and many hosts are turning global\_registers off, so your form code really needs to specify a method of sending the data, and the PHP which processes it needs to use the same method.

---

<div class="post-metadata">

### Author: ![friedo](https://avatars.discourse-cdn.com/v4/letter/f/8edcca/32.png) [@friedo](https://boards.straightdope.com/u/friedo)
#### Post date: [May 22, 2009, 12:52am UTC](https://boards.straightdope.com/t/is-there-a-point-specifying-an-action-for-html-forms/497222/8 "2009-05-22T00:52:36Z")

</div>

Method != Action.
