最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - I cant figure out what this form "action" means - Stack Overflow

programmeradmin1浏览0评论

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?

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?

Share Improve this question edited Nov 7, 2012 at 9:59 Paul D. Waite 99k57 gold badges203 silver badges271 bronze badges asked Nov 7, 2012 at 9:31 AbelAbel 5942 gold badges5 silver badges21 bronze badges 1
  • Basically it just says that something located at <host>/contact-us/ is supposed to handle a POST request. – jensgram Commented Nov 7, 2012 at 9:37
Add a ment  | 

3 Answers 3

Reset to default 2

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./tags/att_form_action.asp

http://www.w3schools./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./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./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.

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.

发布评论

评论列表(0)

  1. 暂无评论