package main import ( "html/template" "log" "net/http" "github.com/yassinebenaid/godump" "gitnet.fr/deblan/go-form/example" "gitnet.fr/deblan/go-form/theme" ) func main() { http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { data := example.ExampleData{} f := example.CreateDataForm() f.Mount(data) if r.Method == f.Method { f.HandleRequest(r) if f.IsSubmitted() && f.IsValid() { f.Bind(&data) godump.Dump(data) } } render := theme.NewRenderer(theme.Html5) tpl, _ := template.New("page").Funcs(render.FuncMap()).Parse(` Form
Submitted {{ .Form.IsSubmitted }}
Valid {{ .Form.IsValid }}
Data
{{ .Dump }}
{{ form .Form }} `) var dump godump.Dumper dump.Theme = godump.Theme{} w.Header().Set("Content-Type", "text/html; charset=utf-8") tpl.Execute(w, map[string]any{ "Form": f, "Dump": template.HTML(dump.Sprint(data)), }) }) http.HandleFunc("/bootstrap", func(w http.ResponseWriter, r *http.Request) { data := example.ExampleData{} f := example.CreateDataForm() f.WithAction("/bootstrap") f.Mount(data) if r.Method == f.Method { f.HandleRequest(r) if f.IsSubmitted() && f.IsValid() { f.Bind(&data) godump.Dump(data) } } render := theme.NewRenderer(theme.Bootstrap5) tpl, _ := template.New("page").Funcs(render.FuncMap()).Parse(` Form
Submitted {{ .Form.IsSubmitted }}
Valid {{ .Form.IsValid }}
Data
{{ .Dump }}
{{ form .Form }}
`) var dump godump.Dumper dump.Theme = godump.Theme{} w.Header().Set("Content-Type", "text/html; charset=utf-8") tpl.Execute(w, map[string]any{ "Form": f, "Dump": template.HTML(dump.Sprint(data)), }) }) log.Fatal(http.ListenAndServe(":1122", nil)) }