vendredi 18 août 2017

Form Always Empty

I've been building a Go todo list and I'm trying to add the ability to add new items, but every time I access the form value, it comes out empty. Here's the handler I built:

func addHandler(w http.ResponseWriter, r *http.Request) {
    err := r.ParseForm()
    if err != nil {
        fmt.Print(err)
    }
    cook, _ := r.Cookie("userid")
    id := cook.Value
    r.ParseForm()
    text := r.FormValue("todo")
    addTodo(text,id) //inserts into database
    http.Redirect(w,r,"/todo",http.StatusFound)
}

And here's the html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<table>
    
    <tr><td></td><td><a href="/delete/">delete</a></td></tr>
    
</table>
<form action="/add" method="post"><input type="text" name="todo"><button type="submit">Add</button></form>
</body>
</html>




Aucun commentaire:

Enregistrer un commentaire