亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

使用 Golang 和 Bootstrap 時表單數據始終為空

使用 Golang 和 Bootstrap 時表單數據始終為空

Go
慕工程0101907 2023-08-07 15:27:56
所以我嘗試使用 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法弄清楚。
查看完整描述

1 回答

?
隔江千里

TA貢獻1906條經驗 獲得超10個贊

元素中缺少name?屬性<input>。如果 name 屬性未設置或為空,則輸入值不會包含在提交的表單中。

像這樣修復:

????<div?class="form-group">
????????<label>Name</label>
????????<input?type="text"?name="name"?id="name"?class="form-control"?placeholder="Enter?name">
????</div>

...其他輸入元素依此類推。


查看完整回答
反對 回復 2023-08-07
  • 1 回答
  • 0 關注
  • 168 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號