If you remember from the forms tutorial, the <form> tag has two attributes. The action=”” attribute tells the form where to send the data that is received from the <input> tag. The method=”” attribute tells the form how to send the data, either as a GET request or a POST request. We can see this by putting a web address in the action attribute. Below, I used action=”http://www.wikipedia.org” to send the data in the form to Wikipedia. Don’t forget, the http://www is required.
Now, clicking on our Login button sends the data, and us, to Wikepedia’s home page.
For this tutorial, I am going to leave out the action and method attributtes. By default, the action attribute is set to our current page and the method attribute default is GET.
Now when we send out the form, the page is refreshed and the input boxes are cleared.
We can see data our form is sending by naming the data. We do this with a name=”” attribute in the <input> tag.
Above, I named the usename input “uname” and the password input “pw”. If we refresh and login now, you will notice that the browser adds what is called a query string to our address bar with our username that we called “name” and the password that we called “pw”.
The query string is everything after the ?. We see what we input for our username, in this case ABCDEF, an ampersand, and the password, 123456.
We should learn two things from this. First: DON’T SEND PASSWORDS USING THE GET METHOD! We DON’T want our passwords showing up in the address bar of the browser! Remember, the GET method is used for GETTING information. For sending information, use the POST method.
Secondly, and the main point of this post, is that we need to name our data in order to retrieve and use it. Before we used the name=”” attribute, the browser didn’t have anything to associate the values we were typing in with. Think of it this way, if I were to walk up to you and say 24, you wouldn’t know what I was talking about. But if I say hours in a day=24, you would know, hopefully, that I was saying that there are 24 hours in a day.
Attribute To Remember
AND DON’T USE THE GET METHOD TO SEND INFORMATION, ESPECIALLY PASSWORDS!