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.
Answer from MEURSAULT on Stack OverflowAction 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.
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).
new_post.html
<form action="/post/new" method="Post"> to the website_names/post.new route.
If I am not mistaken the action form accepts the data from the website_name/post/new in the example above.
new_post.html
<form action " " method="Post">
What do the double empty quotes mean? Does it just fill in the form depending on the route?
My next question is imagine I have 2 routes in python flask that sends data to new_post.html.
The 2 routes in python flask are "post/new" and "/post/edit/<int:post_id>".
If I include the first example of new_post.hmtl could this lead to 500 error if I use the "/post/edit/<int:post_id>" ?
Should I ask this in the flask sub reddit or is here okay?
In forms
Action refers
to Where to send the form-data when the form is submitted
and methods refers to
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 The length of a URL is limited (about 3000 characters) Never use GET to send sensitive data! (will be visible in the URL) Useful for form submissions where a user want to bookmark the result GET is better for non-secure data, like query strings in Google
Notes on POST:
Appends form-data inside the body of the HTTP request (data is not shown is in URL) Has no size limitations Form submissions with POST cannot be bookmarked
http://www.w3schools.com/tags/att_form_action.asp
http://www.w3schools.com/tags/att_form_method.asp
<form action=""> is like <a href=""> - it specifies the URL that the browser will request when the form is submitted.
The URL for both action and href can be relative or absolute. contact.php is relative to the current page, so when a form with that action is submitted, the browser will take the current page’s URL, remove everything after the last /, append contact.php, and submit the form to that URL. E.g.
http://stackoverflow.com/questions/13266788/contact.php
In contrast, /contact-us/#gf_1 starts with a /, so it’s relative to the current domain. In this case, the browser will take the domain of the current page, append /contactus/#gf_1 to that, and submit the form there. E.g.
http://stackoverflow.com/contact-us/#gf_1
In URLs, the hash (#) character starts the fragment identifier. This refers to an anchor point on the page, indicated in the HTML by either a named anchor tag (e.g. <a name="gf_1"></a>) or an id attribute on any tag (e.g. <p id="gf_1"></p>).
By convention, when a browser goes to a URL with a fragment identifier, it will scroll the anchor point referred to by that fragment identifier into view when the page loads.
The fragment identifier is not sent to the server, so by itself it won’t have any effect on a form submission. However, JavaScript running on the page can look at the fragment identifier, and could send an AJAX request to the server based on it.