diff --git a/controllers/home.go b/controllers/home.go index 636bb82..54cc680 100644 --- a/controllers/home.go +++ b/controllers/home.go @@ -16,21 +16,13 @@ func homeHandler(w http.ResponseWriter, r *http.Request) { } func contactHandler(w http.ResponseWriter, r *http.Request) { - views.Template(w, "contact", nil) -} - -func postContactHandler(w http.ResponseWriter, r *http.Request) { - err := r.ParseForm() - checkError(err, w) // bad error handling - mail := parseContactForm(r) - // mail.Send() + if r.Method != http.MethodPost { + views.Template(w, "contact", nil) + return + } + mail := services.NewMail(r.PostFormValue("email"), r.PostFormValue("message")) log.Println(mail) - views.Template(w, "contact_sent", nil) -} - -func parseContactForm(r *http.Request) services.Mail { - log.Println(r.PostForm) - return services.NewMail(r.PostFormValue("email"), r.PostFormValue("message")) + views.Template(w, "contact", struct{ Success bool }{true}) } func checkError(err error, w http.ResponseWriter) { diff --git a/controllers/router.go b/controllers/router.go index 39ffb6e..a234c10 100644 --- a/controllers/router.go +++ b/controllers/router.go @@ -12,7 +12,6 @@ func Router() { http.HandleFunc("/edit/", makeHandler(editHandler)) http.HandleFunc("/save/", makeHandler(saveHandler)) http.HandleFunc("/contact/", contactHandler) - http.HandleFunc("/contact/post/", postContactHandler) http.HandleFunc("/", homeHandler) } diff --git a/views/render.go b/views/render.go index ff9635d..ab5c432 100644 --- a/views/render.go +++ b/views/render.go @@ -5,11 +5,10 @@ import ( "net/http" "text/template" - "github.com/rjNemo/go-wiki/models" "github.com/rjNemo/go-wiki/settings" ) -func Template(w http.ResponseWriter, tmpl string, p *models.Page) { +func Template(w http.ResponseWriter, tmpl string, p interface{}) { // err := templates.ExecuteTemplate(w, "templates/"+tmpl+".html", p) t, err := template.ParseFiles(getTmplName("base"), getTmplName(tmpl)) diff --git a/views/templates/contact.html b/views/templates/contact.html index ce3af72..26eca96 100644 --- a/views/templates/contact.html +++ b/views/templates/contact.html @@ -1,7 +1,15 @@ {{define "title"}} Contact Us | Go-Wiki {{end}} {{define "content"}} +{{if.Success}} +