Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

html

forms

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.

like image 891
user2605845 Avatar asked Jul 22 '13 07:07

user2605845


People also ask

What does action on an HTML form mean?

The HTML form action attribute defines what should happen to data when a form is submitted on a web page. The value of the action attribute should be the URL of the web resource that will process the contents of the form.

How do you input an action in HTML?

The formaction attribute specifies the URL of the file that will process the input control when the form is submitted. The formaction attribute overrides the action attribute of the <form> element. Note: The formaction attribute is used with type="submit" and type="image" .

Does an HTML form have to have an action?

Yes, the form is required to have an action attribute in HTML4. If it's not set, the browser will likely use the same method as providing an empty string to it.


2 Answers

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.

like image 110
Ignacio Vazquez-Abrams Avatar answered Sep 28 '22 00:09

Ignacio Vazquez-Abrams


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

like image 42
AnaMaria Avatar answered Sep 27 '22 23:09

AnaMaria