hdr*_*ven 4 html return-value request go
我有一个html表单,我将值放入数据库中.但是当我插入它们时,值会出现在数据库中,如"".
这是我插入值的方式:
title, author, description := r.Form("title"), r.FormValue("author"), r.FormValue("description")
fmt.Println(title, author, description)
rows, err := db.Query("INSERT INTO apps (title, author, description) VALUES ($1, $2, $3)",
title, author, description)
PanicIf(err)
defer rows.Close()
http.Redirect(w, r, "/myapps", http.StatusFound)
db.Close()
Run Code Online (Sandbox Code Playgroud)
Html:
<form action="/apps" method="POST">
<div class="form-group">
<label>Name</label>
<input type="text" class="form-control" name="title" />
</div>
<div class="form-group">
<label>Author</label>
<input type="text" class="form-control" name="author" />
</div>
<div class="form-group">
<label>Description</label>
<input type="text" class="form-control" name="description" />
</div>
<input type="submit" value="Create" class="btn btn-success" />
<a href="/myapps">
<input type="button" value="Return" class="btn btn-primary" />
</a>
</form>
Run Code Online (Sandbox Code Playgroud)
formvalues可能有问题吗?
在使用/ 之前, 必须先调用r.ParseForm().r.Formr.PostForm
来自:http://golang.org/src/pkg/net/http/request.go#L168
// Form contains the parsed form data, including both the URL
// field's query parameters and the POST or PUT form data.
// This field is only available after ParseForm is called.
// The HTTP client ignores Form and uses Body instead.
Form url.Values
// PostForm contains the parsed form data from POST or PUT
// body parameters.
// This field is only available after ParseForm is called.
// The HTTP client ignores PostForm and uses Body instead.
PostForm url.Values
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
4103 次 |
| 最近记录: |