Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what do <form action="#"> and <form method="post" action="#"> do?

Tags:

html

I'm reading a book on html development (which I'm fairly new at) and despite the fact that the book just had its 1st publishing one month ago (Nov. 2011), the author is an experienced coder and maybe using # for the action in a form is old school?

Because I'm trying to get the gist of the sample code and I cannot find an explanation of form action="#" despite searching for

<form action="#">    

on google, on SO, and in www.w3schools.com.

Anyone know what the # action means for forms?

like image 517
SandHawkerTech Avatar asked Dec 06 '11 04:12

SandHawkerTech


People also ask

What is form action form?

The HTML form action attribute defines where to send the form data when a form is submitted in an HTML document.

What do you put in form action?

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

What is form action and method?

The method attribute specifies how to send form-data (the form-data is sent to the page specified in the action attribute). The form-data can be sent as URL variables (with method="get" ) or as HTTP post transaction (with method="post" ). Notes on GET: Appends form-data into the URL in name/value pairs.

Should I use form 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. You really should set action="" which is perfectly valid HTML4, follows standards, and achieves the same exact result.


1 Answers

Action normally specifies the file/page that the form is submitted to (using the method described in the method paramater (post, get etc.))

An action of # indicates that the form stays on the same page, simply suffixing the url with a #. Similar use occurs in anchors. <a href=#">Link</a> for example, will stay on the same page.

Thus, the form is submitted to the same page, which then processes the data etc.

like image 71
MEURSAULT Avatar answered Sep 27 '22 20:09

MEURSAULT