Compare commits
7 Commits
d6540d5764
...
formular_a
Author | SHA1 | Date | |
---|---|---|---|
71bf8978ac | |||
babbe137e4 | |||
cb6f83139f | |||
48f104650f | |||
32fbd1d28d | |||
e18fb0d158 | |||
16240b8c01 |
67
main.go
67
main.go
@ -1,3 +1,68 @@
|
||||
package main
|
||||
|
||||
func main() {}
|
||||
import (
|
||||
"fmt"
|
||||
"html/template"
|
||||
"log"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type Person struct {
|
||||
FirstName string
|
||||
LastName string
|
||||
}
|
||||
|
||||
type Instructor Person
|
||||
|
||||
type Participant struct {
|
||||
ID int64
|
||||
Person
|
||||
Company string
|
||||
}
|
||||
|
||||
type Briefing struct {
|
||||
Instructor
|
||||
Date string
|
||||
Time string
|
||||
State string
|
||||
Location string
|
||||
Participants []Participant
|
||||
}
|
||||
|
||||
func main() {
|
||||
var i, j int64
|
||||
var b Briefing
|
||||
|
||||
mux := http.NewServeMux()
|
||||
i = 1
|
||||
|
||||
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static/"))))
|
||||
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
|
||||
template.Must(template.ParseFiles("templates/index.html")).Execute(w, i)
|
||||
})
|
||||
mux.HandleFunc("/add-participant/", func(w http.ResponseWriter, r *http.Request) {
|
||||
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))
|
||||
}
|
||||
|
@ -10,10 +10,59 @@
|
||||
|
||||
<body>
|
||||
<h1>Sicherheitsunterweisung</h1>
|
||||
|
||||
<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">
|
||||
<label for="date-input">Datum</label>
|
||||
<input type="date" name="date" id="date-input" />
|
||||
</div>
|
||||
|
||||
<div id="time">
|
||||
<label for="time-input">Uhrzeit</label>
|
||||
<input type="time" name="time" id="time-input" />
|
||||
</div>
|
||||
|
||||
<div id="state">
|
||||
<label for="state-input">Stand vom</label>
|
||||
<input type="date" name="state" id="state-input" />
|
||||
</div>
|
||||
|
||||
<div id="location">
|
||||
<label for="location-input">Ort</label>
|
||||
<input type="text" name="location" id="location-input" />
|
||||
</div>
|
||||
|
||||
<div id="participants">
|
||||
<button type="button" hx-post="/add-participant/" hx-target="#participants" hx-swap="beforeend"
|
||||
hx-trigger="click">
|
||||
+
|
||||
</button>
|
||||
|
||||
<div id="participant-{{ . }}">
|
||||
<label for="participant-first-input-{{ . }}">Vorname</label>
|
||||
<input type="text" name="participant-first-{{ . }}" id="participant-first-input-{{ . }}" />
|
||||
|
||||
<label for="participant-last-input-{{ . }}">Nachname</label>
|
||||
<input type="text" name="participant-last-{{ . }}" id="participant-last-input-{{ . }}" />
|
||||
|
||||
<label for="participant-company-input-{{ . }}">Firma</label>
|
||||
<input type="text" name="participant-company-{{ . }}" id="participant-company-input-{{ . }}" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<button type="submit" hx-post="/submit/">
|
||||
Senden
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<script src="/static/js/htmx.min.js" type="text/javascript"></script>
|
||||
</body>
|
||||
|
||||
|
12
templates/participant.html
Normal file
12
templates/participant.html
Normal file
@ -0,0 +1,12 @@
|
||||
{{ define "participant" }}
|
||||
<div id="participant-{{ . }}">
|
||||
<label for="participant-first-input-{{ . }}">Vorname</label>
|
||||
<input type="text" name="participant-first-{{ . }}" id="participant-first-input-{{ . }}" />
|
||||
|
||||
<label for="participant-last-input-{{ . }}">Nachname</label>
|
||||
<input type="text" name="participant-last-{{ . }}" id="participant-last-input-{{ . }}" />
|
||||
|
||||
<label for="participant-company-input-{{ . }}">Firma</label>
|
||||
<input type="text" name="participant-company-{{ . }}" id="participant-company-input-{{ . }}" />
|
||||
</div>
|
||||
{{ end }}
|
Reference in New Issue
Block a user