DEV Community

Ega Prasetya
Ega Prasetya

Posted on

Golang Web - Form Value

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.

Top comments (1)

Collapse
 
sultan3015 profile image
Abdulrahman Daud Miraj

Bro
What if the data am picking from the front-end is a drop-down selection