Added guestbook POST handler for forms.
This commit is contained in:
parent
a81e71eb87
commit
d183c42825
@ -12,6 +12,7 @@ import (
|
||||
"git.arav.top/Arav/dwelling-home/pkg/util"
|
||||
"git.arav.top/Arav/dwelling-home/web"
|
||||
gbsqlite "git.arav.top/Arav/justguestbook/database/sqlite"
|
||||
"git.arav.top/Arav/justguestbook/guestbook"
|
||||
)
|
||||
|
||||
type Handlers struct {
|
||||
@ -116,6 +117,34 @@ func (h *Handlers) Guestbook(w http.ResponseWriter, r *http.Request) {
|
||||
web.Guestbook("/ Guestbook", h.guestbookOwner, "", pageCount, entries, r, w)
|
||||
}
|
||||
|
||||
func (h *Handlers) GuestbookPost(w http.ResponseWriter, r *http.Request) {
|
||||
var entry *guestbook.Entry
|
||||
var err error
|
||||
|
||||
if r.Header.Get("Content-Type") == "application/x-www-form-urlencoded" {
|
||||
r.ParseForm()
|
||||
|
||||
if r.FormValue("name") == "" {
|
||||
r.Form.Set("name", "Anonymous")
|
||||
}
|
||||
|
||||
entry, err = guestbook.NewEntry(r.FormValue("name"), r.FormValue("message"),
|
||||
r.FormValue("website"), r.FormValue("hide_website") != "")
|
||||
if err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if err = h.guestbookDB.NewEntry(entry); err != nil {
|
||||
http.Error(w, err.Error(), http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
http.Redirect(w, r, "/guestbook", http.StatusMovedPermanently)
|
||||
}
|
||||
|
||||
func (h *Handlers) RSS(w http.ResponseWriter, r *http.Request) {
|
||||
posts := []mindflow.Post{
|
||||
{Category: "Kek", Date: time.Now(), Title: "LMAO", Body: "Testing!"},
|
||||
|
Loading…
Reference in New Issue
Block a user