Eingabemaske funktioniert soweit
i und j sollten jetzt richtig verwendet werden
This commit is contained in:
parent
babbe137e4
commit
61c895d53f
28
main.go
28
main.go
@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"html/template"
|
"html/template"
|
||||||
"log"
|
"log"
|
||||||
"net/http"
|
"net/http"
|
||||||
@ -14,7 +15,7 @@ type Person struct {
|
|||||||
type Instructor Person
|
type Instructor Person
|
||||||
|
|
||||||
type Participant struct {
|
type Participant struct {
|
||||||
id int64
|
ID int64
|
||||||
Person
|
Person
|
||||||
Company string
|
Company string
|
||||||
}
|
}
|
||||||
@ -29,8 +30,11 @@ type Briefing struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var i, j int64
|
||||||
|
var b Briefing
|
||||||
|
|
||||||
mux := http.NewServeMux()
|
mux := http.NewServeMux()
|
||||||
i := 1
|
i, j = 1, 1
|
||||||
|
|
||||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
||||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -38,8 +42,28 @@ func main() {
|
|||||||
})
|
})
|
||||||
mux.HandleFunc("/add-participant/", func(w http.ResponseWriter, r *http.Request) {
|
mux.HandleFunc("/add-participant/", func(w http.ResponseWriter, r *http.Request) {
|
||||||
i++
|
i++
|
||||||
|
j = i
|
||||||
template.Must(template.ParseFiles("templates/index.html", "templates/participant.html")).ExecuteTemplate(w, "participant", 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 <= 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))),
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
log.Fatalln(http.ListenAndServe(":8080", mux))
|
log.Fatalln(http.ListenAndServe(":8080", mux))
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,14 @@
|
|||||||
<h1>Sicherheitsunterweisung</h1>
|
<h1>Sicherheitsunterweisung</h1>
|
||||||
|
|
||||||
<form>
|
<form>
|
||||||
|
<div id="instructor">
|
||||||
|
<label for="instructor-first-input">Unterweiser Vorname</label>
|
||||||
|
<input type="text" name="instructor-first" id="instructor-first-input" />
|
||||||
|
|
||||||
|
<label for="instructor-last-input">Unterweiser Nachname</label>
|
||||||
|
<input type="text" name="instructor-last" id="instructor-last-input" />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="date">
|
<div id="date">
|
||||||
<label for="date-input">Datum</label>
|
<label for="date-input">Datum</label>
|
||||||
<input type="date" name="date" id="date-input" />
|
<input type="date" name="date" id="date-input" />
|
||||||
@ -40,13 +48,13 @@
|
|||||||
|
|
||||||
<div id="participant-{{ . }}">
|
<div id="participant-{{ . }}">
|
||||||
<label for="participant-first-input-{{ . }}">Vorname</label>
|
<label for="participant-first-input-{{ . }}">Vorname</label>
|
||||||
<input type="text" name="participant-first" id="participant-first-input-{{ . }}" />
|
<input type="text" name="participant-first-{{ . }}" id="participant-first-input-{{ . }}" />
|
||||||
|
|
||||||
<label for="participant-last-input-{{ . }}">Nachname</label>
|
<label for="participant-last-input-{{ . }}">Nachname</label>
|
||||||
<input type="text" name="participant-last" id="participant-last-input-{{ . }}" />
|
<input type="text" name="participant-last-{{ . }}" id="participant-last-input-{{ . }}" />
|
||||||
|
|
||||||
<label for="participant-company-input-{{ . }}">Firma</label>
|
<label for="participant-company-input-{{ . }}">Firma</label>
|
||||||
<input type="text" name="participant-company" id="participant-company-input-{{ . }}" />
|
<input type="text" name="participant-company-{{ . }}" id="participant-company-input-{{ . }}" />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -1,12 +1,12 @@
|
|||||||
{{ define "participant" }}
|
{{ define "participant" }}
|
||||||
<div id="participant-{{ . }}">
|
<div id="participant-{{ . }}">
|
||||||
<label for="participant-first-input-{{ . }}">Vorname</label>
|
<label for="participant-first-input-{{ . }}">Vorname</label>
|
||||||
<input type="text" name="participant-first" id="participant-first-input-{{ . }}" />
|
<input type="text" name="participant-first-{{ . }}" id="participant-first-input-{{ . }}" />
|
||||||
|
|
||||||
<label for="participant-last-input-{{ . }}">Nachname</label>
|
<label for="participant-last-input-{{ . }}">Nachname</label>
|
||||||
<input type="text" name="participant-last" id="participant-last-input-{{ . }}" />
|
<input type="text" name="participant-last-{{ . }}" id="participant-last-input-{{ . }}" />
|
||||||
|
|
||||||
<label for="participant-company-input-{{ . }}">Firma</label>
|
<label for="participant-company-input-{{ . }}">Firma</label>
|
||||||
<input type="text" name="participant-company" id="participant-company-input-{{ . }}" />
|
<input type="text" name="participant-company-{{ . }}" id="participant-company-input-{{ . }}" />
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user