diff --git a/main.go b/main.go index 7de6c65..fe552d4 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,7 @@ package main import ( + "fmt" "html/template" "log" "net/http" @@ -14,7 +15,7 @@ type Person struct { type Instructor Person type Participant struct { - id int64 + ID int64 Person Company string } @@ -29,8 +30,11 @@ type Briefing struct { } func main() { + var i, j int64 + var b Briefing + mux := http.NewServeMux() - i := 1 + i = 1 mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/")))) mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { @@ -40,6 +44,25 @@ func main() { i++ template.Must(template.ParseFiles("templates/index.html", "templates/participant.html")).ExecuteTemplate(w, "participant", i) }) + mux.HandleFunc("/submit/", func(w http.ResponseWriter, r *http.Request) { + b.Instructor.FirstName = r.PostFormValue("instructor-first") + b.Instructor.LastName = r.PostFormValue("instructor-last") + b.Date = r.PostFormValue("date") + b.Time = r.PostFormValue("time") + b.State = r.PostFormValue("state") + b.Location = r.PostFormValue("location") + for j = 1; j <= i; j++ { + b.Participants = append(b.Participants, Participant{ + ID: j, + Person: Person{ + FirstName: r.PostFormValue("participant-first-" + fmt.Sprint(j)), + LastName: r.PostFormValue(("participant-last-" + fmt.Sprint(j))), + }, + Company: r.PostFormValue(("participant-company-" + fmt.Sprint(j))), + }) + } + fmt.Println(b) + }) log.Fatalln(http.ListenAndServe(":8080", mux)) } diff --git a/templates/index.html b/templates/index.html index b78607d..452bf83 100644 --- a/templates/index.html +++ b/templates/index.html @@ -12,6 +12,14 @@

Sicherheitsunterweisung

+
+ + + + + +
+
@@ -40,13 +48,13 @@
- + - + - +
diff --git a/templates/participant.html b/templates/participant.html index 382f2af..9ed45a6 100644 --- a/templates/participant.html +++ b/templates/participant.html @@ -1,12 +1,12 @@ {{ define "participant" }}
- + - + - +
{{ end }}