If we want users to be able to post their own greetings, we need a way to
process information submitted by the user with a web form. The Go
http package makes processing form data easy.
Handling Web Forms
Replace the contents of
myapp/hello.go with the
Reload the page to see the form, then try submitting a message.
This version has two handlers: the path
/ is mapped to
root, which displays a web form. The path
sign, which displays the data submitted by the web form.
sign function gets the form data by calling
r.FormValue and passes it to
that writes the rendered template to the
In the template code, the content is automatically filtered to escape
HTML special characters. The automatic escaping is a property of the
as distinct from text/template.
Now that we can collect information from the user, we need a place to put it and a way to get it back.