user2605845
user2605845

Reputation: 300

What does an entry "action='?'" in html form mean?

I have found an entry in html file

'<form action="?" ... '

I do not understand what it does. Search in Google returned no results. Actually it is a Django template file, but I didn't find anything in django template documentation.

Upvotes: 29

Views: 22865

Answers (6)

NivF007
NivF007

Reputation: 271

'<form action="?" ... ' strips the query string off of the URL when submitting the form, and submits the form to the current document address (i.e. itself).

Here is what that means:

Let's use the following URL as example:

ExampleSite.com**?SearchTerm1=chocolate&SearchTerm2=cake**

This URL contains the query string '?SearchTerm1=chocolate&SearchTerm2=cake' and sends that query string to the web site server, attached to the URL.

Sometimes, you want to ensure that the URL being passed to the server is stripped of any query strings (i.e. the query is string is removed completely) and only the URL is passed.

Let's say you bookmarked the page, using the full URL and query string ExampleSite.com?SearchTerm1=chocolate&SearchTerm2=cake****

Now you get to that page, and there is a search form.

You decide to use the search form to search for something new...

'<form action="?" ... ', as used above, removes the query string from the URL when the form is submitted, and submits the form to the same page that it came from (usually a 'controller' (a page with programming that determines what to do with the information sent to it by the user) ).

Upvotes: 4

bakslash
bakslash

Reputation: 11

action is an attribute used in forms to specify the URL of the file that will process the input control when form is submitted

Upvotes: -1

ShivarajRH
ShivarajRH

Reputation: 940

When we don't know the url to go by submit the form we can specify like this, It will reload the same page by appending question mark(?) to url.

I.e, Form is submitted for same page itself. It identifies form is reloaded.

Note: We can leave action property blank, even though it will work!

Upvotes: 1

topfun
topfun

Reputation: 11

<form name="test" action="process.php" method="get">
<input type="submit" value="Submit">

The action used here will take you to the process.php page after clicking the submit button. In short the action= is used to go to the specified page(mentioned in the action=) after filling the form and submitting.

Upvotes: 1

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798536

It uses the current URL with an empty query string as the action of the form. An empty query string. Empty. Meaning no query string at all. The query string will be no more. It will not be used. It will be gone. There will be no more query string after submitting the form. The query string will have vanished. Disappeared. Gone away. Become no more.

Upvotes: 41

AnaMaria
AnaMaria

Reputation: 3621

The action= atrribute has only value. i.e URL. In simple english once your form is processed and you hit a submit button or enter you will be redirected to the URL you give to the action attribute

Example:

<form action="demo_form.asp" method="get">
  First name: <input type="text" name="fname"><br>
  Last name: <input type="text" name="lname"><br>
  <input type="submit" value="Submit">
</form>

In the case of you question, if the action is "?" then the returned hash-string will be current URL plus "/?" appended which will take you back to the same page you were on.

action="" will resolve to the page's address. action="?" will resolve to the page's address + ?, which will mean an empty fragment identifier.

Doing the latter might prevent a navigation (new load) to the same page and instead try to jump to the element with the id in the fragment identifier. But, since it's empty, it won't jump anywhere.

Usually, authors just put # in href-like attributes when they're not going to use the attribute where they're using scripting instead. In these cases, they could just use action="" (or omit it if validation allows).

Upvotes: 6

Related Questions