Skip to content

Latest commit

 

History

History
 
 

upload-form

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 

Upload form data

  1. HTML form có dạng:
<!-- Gửi POST request lên /register -->
<form action="/register" method="POST">
    <div class="container">
        <h1>Đăng kí tài khoản</h1>
        <hr>
    
        <label for="email"><b>Email</b></label>
        <input type="text" placeholder="Nhập Email" name="email" required>
    
        <label for="password"><b>Password</b></label>
        <input type="password" placeholder="Nhập Password" name="password" required>
    
        <hr>
    
        <button type="submit" class="registerbtn">Đăng kí</button>
    </div>
</form>
  1. Đăng kí GET route trả về form đăng kí trên
func registerPage(c *gin.Context) {
	c.HTML(http.StatusOK, "form.html", gin.H{})
}

router.GET("/form", registerPage)
  1. Đăng kí POST route /register để nhận form data
func getFormData(c *gin.Context) {
	email := c.PostForm("email")
	password := c.PostForm("password")

	log.Println("Email:", email)
	log.Println("Password:", password)
}

router.POST("/register", getFormData)