Original post

I have a website and want to read out values from a form.

This is a part of my html:

 <form action="/adduser" method="POST"> <input type="text" placeholder="User Name" name="username" id="uname"/> <button type="submit">Add User</button> </form> 


package main import ( "fmt" "log" "net/http" "github.com/gorilla/mux" ) //ADD USER: Read Input Form func adduser(w http.ResponseWriter, r *http.Request) { //Call to ParseForm makes form fields available. err := r.ParseForm() if err != nil { // Handle error here via logging and then return } else if r.Method != "POST" { http.Redirect(w, r, "/", http.StatusSeeOther) } addusername := r.PostFormValue("username") fmt.Println("%s", adduser) } //HTTP SERVER func main() { r := mux.NewRouter() r.PathPrefix("/").Handler(http.FileServer(http.Dir("./html"))) r.HandleFunc("/adduser", adduser) log.Println("Listening at port 8080") log.Fatal(http.ListenAndServe(":8080", r)) } 

Why doesn’t that get me printed out the username ?

Thank you for your help.

submitted by /u/cevinxf
[link] [comments]