My button does not save the form to the database. Help please

I am trying to save this form for an attendance website. But whenever I clicked the clock in button it does not save the data to the database.

code:

 if response.method == "POST":
        form = CreateNewList(response.POST) 
        if response.POST.get("clockIn"):
            if form.is_valid():
                n = form.cleaned_data["name"]
                t = Name(name = n, timeIn=datetime.now())
                t.save()    
 else: 
        form = CreateNewList()        
    return render(response, "main/home.html", {"form":form})

html button code:

 <button type="submit" ,name="clockIn", value="time In" class="btn-success">Clock In</button>

I have also tried using this:

if 'clockIn' in response.POST:
            if form.is_valid():
                n = form.cleaned_data["name"]
                t = Name(name = n, timeIn=datetime.now())
                t.save()    

It still does not work. Help please.

1 answer

  • answered 2021-04-08 03:14 Biplove Lamichhane

    There should not be comma(,) between the attributes in html tag. So:

     <button type="submit" name="clockIn" value="time In" class="btn-success">Clock In</button>