ch8.1
This commit is contained in:
@@ -70,7 +70,9 @@ func (app *application) snippetView(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
|
||||
func (app *application) snippetCreate(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("Display the form for creating a new snippet..."))
|
||||
data := app.newTemplateData(r)
|
||||
|
||||
app.render(w, http.StatusOK, "create.tmpl", data)
|
||||
}
|
||||
|
||||
func (app *application) snippetCreatePost(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -83,5 +85,5 @@ func (app *application) snippetCreatePost(w http.ResponseWriter, r *http.Request
|
||||
app.serverError(w, err)
|
||||
return
|
||||
}
|
||||
http.Redirect(w, r, fmt.Sprintf("/snippet/view?id=%d", id), http.StatusSeeOther)
|
||||
http.Redirect(w, r, fmt.Sprintf("/snippet/view/%d", id), http.StatusSeeOther)
|
||||
}
|
||||
|
||||
23
ui/html/pages/create.tmpl
Normal file
23
ui/html/pages/create.tmpl
Normal file
@@ -0,0 +1,23 @@
|
||||
{{define "title"}}Create a New Snippet{{end}}
|
||||
|
||||
{{define "main"}}
|
||||
<form action='/snippet/create' method='POST'>
|
||||
<div>
|
||||
<label>Title:</label>
|
||||
<input type='text' name='title'>
|
||||
</div>
|
||||
<div>
|
||||
<label>Content:</label>
|
||||
<textarea name='content'></textarea>
|
||||
</div>
|
||||
<div>
|
||||
<label>Delete in:</label>
|
||||
<input type='radio' name='expires' value='365' checked> One Year
|
||||
<input type='radio' name='expires' value='7'> One Week
|
||||
<input type='radio' name='expires' value='1'> One Day
|
||||
</div>
|
||||
<div>
|
||||
<input type='submit' value='Publish snippet'>
|
||||
</div>
|
||||
</form>
|
||||
{{end}}
|
||||
@@ -1,5 +1,6 @@
|
||||
{{define "nav"}}
|
||||
<nav>
|
||||
<a href='/'>Home</a>
|
||||
<a href='/snippet/create'>Create snippet</a>
|
||||
</nav>
|
||||
{{end}}
|
||||
Reference in New Issue
Block a user