I am making an pizza website and I am working on the status of the order. The order is working, but if i type my email in the input place, it doesn't show my status.
The HTML:
<form method="POST">
<p>Emailadres <input type="email" name="statuscheck"></p>
<input type="submit" value="Verzend">
</form>
{{ . }}
The Handler:
func statusHandler(writer http.ResponseWriter, request *http.Request) {
log.Println("Viewing status")
// maak een html template object aan
statuschecktemplate, _ := template.ParseFiles("./templates/status.htm")
PizzaBestellingen, _ := LoadBestellingenFromMap()
var data string
for _, value := range PizzaBestellingen {
for _, value := range value {
if value.Email == request.FormValue("statuscheck") {
data = value.Status
}
}
}
fmt.Println(data)
// genereer de html met de lijst van pizzas
// deze worden automatisch teruggestuurd naar de browser
statuschecktemplate.Execute(writer, data)
}
Looking at its definition,
func LoadBestellingenFromMap() (map[string][]Klant, error) {
LoadBestellingenFromMap
returns a map
to a slice
of Klant
s, not just one.
You might try something like:
for _, values := range PizzaBestellingen {
for _, value := range Values {
if value.Email == request.FormValue("statuscheck") {
data = value.Status
}
}
}
It's possible you'll also have to reconsider the logic of your algorithm ( you could get more than one such Email
), but that is already be the case, since you were already iterating across PizzaBestellingen
anyway. Keep it in mind if it's possible more than one such email would match.