DEV Community

loading...

Golang Web - Form Value

Ega Prasetya
No matter what i`m learn, kill with documentation.
・1 min read

In this chapter we will learn how to submit the data, from layer FrontEnd to BackEnd, so lets do it..

FRONT END

Prepare a new folder and a template view.html on this file needs to be defined 2 template, which are form and result. The first template (form) became as the landing page program and the contents of the invitation to submit the data.

Alt Text

BACK END

Open file main.go, in this file 2 route handler registration.

  • Route / is a landing page, show the form input.
  • Route /process as a action from input, show the text.

Alt Text

Handler route / wrapped in a function called routeIndexGet. Within it template form in the template view.html will be rendered to view. The request in this handler is restricted to method get only, the request by method will result in a response of 400 Bad Request.

Alt Text

Alt Text

TEST

So now run the program that we have created.

Alt Text

Alt Text

Finally! Try at home.

Discussion (0)