DEV Community

Ega Prasetya
Ega Prasetya

Posted on

5 1

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.

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

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

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

AWS GenAI LIVE!

GenAI LIVE! is a dynamic live-streamed show exploring how AWS and our partners are helping organizations unlock real value with generative AI.

Tune in to the full event

DEV is partnering to bring live events to the community. Join us or dismiss this billboard if you're not interested. ❤️