所以我嘗試使用 bootstrap 創建一個表單并在 golang 中解析它,但表單數據始終返回為空。戈蘭: // CreateEmployee - handler function for creating a new employeefunc CreateEmployee(w http.ResponseWriter, r *http.Request) { err := r.ParseForm() if err != nil { fmt.Println(err.Error()) } fmt.Println(r.Form)}引導形式:<html><head><title></title><link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous"></head><body> <form action="/employee" method="post"> <div class="form-group"> <label>Name</label> <input type="text" id="name" class="form-control" placeholder="Enter name"> </div> <div class="form-group"> <label>Title</label> <input type="text" id="title" class="form-control" placeholder="Enter title"> </div> <div class="form-group"> <label>Email</label> <input type="email" id="email" class="form-control" placeholder="Enter email"> </div> <div class="form-group"> <label>Photo</label> <input type="text" id="photo" class="form-control" placeholder="Enter photo location"> </div> <div class="form-group"> <label>Phonetic</label> <input type="text" id="phonetic" class="form-control" placeholder="Enter phonetic pronunciation"> </div> <button type="submit" class="btn btn-primary">Submit</button> </form></body>我知道您必須在填充 r.Form 之前調用 ParseForm,但據我所知,這就是所需的全部。該路線工作正常,因為當我提交表單時,它正在將空地圖打印到控制臺??磥砦以谧鲆恍┯薮赖氖虑椋珶o法弄清楚。
使用 Golang 和 Bootstrap 時表單數據始終為空
慕工程0101907
2023-08-07 15:27:56