Reputation: 594
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?
Upvotes: 5
Views: 2068
Reputation: 943217
It's a URI (although one with a fragment identifier in it, which is unusual for a form action).
Sometimes a URI lets you infer what technologies the server will use to generate the response for it. This isn't one of those URIs.
It might use PHP. It might not. There are certainly plenty of technologies that could be used (Perl, Python, JavaScript, Ruby, Java, .NET, etc, etc, etc). There is no way to tell which is being used from that HTML.
The technologies involved should only matter to the people who have the access to change them though, and those people can look on the server to see how the URI would be handled.
Since all of them can handle everything that a contact form would need on the server, knowing what that particular example uses wouldn't provide any insight into building your own.
Upvotes: 2
Reputation: 98786
<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.
Upvotes: 2
Reputation: 9457
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
Upvotes: 2