Could someone explain what method or how a form thats using this code works?
<form method='post' enctype='multipart/form-data' target='gform_ajax_frame_1' id='gform_1'
action='/contact-us/#gf_1'>
</form>
I'm trying to learn more about forms, and right now I'm trying to build a multipart form like one of my friends did.
I'm used to forms saying action="contact.php"
but this one says action="/contact_us/#gf_1"
. What does it mean?
The HTML form action attribute defines where to send the form data when a form is submitted in an HTML document.
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.
Is the action Attribute Required? Back in HTML4, the answer would be yes. Nowadays with HTML5, you are not required to specify an action attribute. If you have a form tag without an action attribute then the data will be sent to its own page.
A form without an action attribute is not a form, according to standards - and will actually cause a page reload in some browsers.. I've found that action="javascript:void(0);" works well.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With