Ejemplo n.º 1
0
func HouseNew(w http.ResponseWriter, r *http.Request, _ mux.Params) {
	title := "new"
	p, err := views.loadPage(title)
	if err != nil {
		p = &views.Page{Title: title}
	}
	t, _ := template.ParseFiles(title + ".html")
	t.Execute(w, p)
}
Ejemplo n.º 2
0
func HouseCreate(w http.ResponseWriter, r *http.Request, _ mux.Params) {
	title := "new"
	p, err := views.loadPage(title)
	if err != nil {
		p = &views.Page{Title: title}
	}
	fmt.Println("method:", r.Method)
	if r.Method == "GET" {
		t, _ := template.ParseFiles(title + ".html")
		t.Execute(w, p)
	} else {
		r.ParseForm()
		// logic part of the form
		/*
		   fmt.Println("address:", r.FormValue("address"))
		   fmt.Println("city:", r.FormValue("city"))
		   fmt.Println("state:", r.FormValue("state"))
		   fmt.Println("state:", r.FormValue("zipcode"))
		   fmt.Println("built in:", r.FormValue("built"))
		   fmt.Println("Owner:", r.FormValue("firstname"), r.FormValue("lastname"))
		   fmt.Println("Status:", r.FormValue("status"))
		   fmt.Println("Detail:", r.FormValue("detail"))
		*/

		for k, v := range r.Form {
			fmt.Println(k, ":", v[0])
		}

		/*
		   data, err := json.Marshal(r.Form)
		   if err != nil {
		       panic(err)
		   }

		   fmt.Println(string(data))
		*/

		/*
		   if err := Save(); err != nil {
		       panic(err)
		       http.Redirect(w, r, "/failed", http.StatusFound)
		   }
		*/

		http.Redirect(w, r, "/houses", http.StatusFound)
	}
}