Forms: Action and Servers

Where does the data in a form go when the form is submitted?

That depends. Code must tell it where to go. In all the examples here, no data is sent to a server. All the form data stays right here, in your browser.

Google Forms give us a good example of how most forms work when they send data to a server to be stored. If you view source, you can find the <form> tag:

<form action="https://docs.google.com/spreadsheet/formResponse?formkey=something&theme=something_else&xyz" method="POST" id="ss-form">

The two attributes action and method are fully explained here: Sending and retrieving form data. Very simply, the action attribute tells the data WHERE to go, and the method attribute tells it HOW to go. In the Google example above, notice that action is a URL (which I have shortened). The method here is "POST"; the other common method is "GET" (one of those is usually used for HTML forms).

When you use GET, the form data will be visible in the address bar of the browser, as is the case with most search engines:

https://www.google.com/search?q=journalism

That does not happen with POST. Clearly, when you are sending lots of data, or confidential data, you need to use POST.

Whether your form uses POST or GET, either way it's an HTTP request, and that means your form has to be live on the Web, and the URL (supplied by action) has to interact with a script that lives on a server. That script might be written in Python or PHP or various other languages -- there are many options -- but you can't run it locally.

Google Forms: To give you a little experience with action and method and how forms store data, I set up a public Google form for you to fill out. Do that now.

After you submit the form, view the data that Google saved from your form and everyone else's in this spreadsheet.

Email or contact forms: Every Web hosting company that's worth using provides a basic form handler program for email. You never need to write your own. The hosting company will provide a template HTML form for you to copy. The key is: You DO NOT CHANGE the action and method in the <form> tag! Also, you will need to type in your own email address, and then whenever someone fills that form on your website and submits it, you'll get a neatly formatted email. Usually you can modify the form as much as you want, as long as you don't change the name or id for any fields provided in the template. (Why? Because the form handler program will look for those, and it will throw an error if they're not found.)

Return to the index.