I have a form which registers a new user, I used Bootstrap 5 to make it look nice. However, when I press the submit button the form does not validate. The error it shows when I write print(form.errors)
says that every field is required, which means it didn't recieve anything. Why does this happen? This is my code:
HTML
<div class="card" id='signup_card'>
<div class='card-header'>
<h2 class='card-title'>Sign Up</h2>
</div>
<div class='card-body'>
<form method='POST' action="" id='create_user_form' style="color: #fff;">
{% csrf_token %}
<label for='usernameInput' class="form-label">{{form.username.label}}:</label>
<input type="text" id='usernameInput' style="margin-bottom: 20px;">
<label for='phoneNumberInput' class="form-label">{{form.phone_number.label}}:</label>
<input type="text" id='phoneNumberInput' style="margin-bottom: 20px;">
<label for='emailInput' class="form-label">{{form.email.label}}:</label>
<input type="text" id='emailInput' style="margin-bottom: 20px;">
<label for='password1Input' class="form-label">{{form.password1.label}}:</label>
<input type="text" id='password1Input' style="margin-bottom: 20px;">
<label for='password2Input' class="form-label">{{form.password2.label}}:</label>
<input type="text" id='password2Input' style="margin-bottom: 20px;">
<button class="btn btn-primary" type='submit'>Submit</button>
</form>
</div>
models.py
class Account(User):
phone_number = BigIntegerField()
forms.py
class CreateAccountForm(UserCreationForm):
class Meta:
model = Account
fields = ['username', 'email', 'phone_number', 'password1', 'password2']
views.py
def signup(request):
if request.method == 'GET':
form = CreateAccountForm()
ctx = {
'form':form
}
return render(request, 'signup.html', ctx)
if request.method == 'POST':
form = CreateAccountForm(request.POST)
if form.is_valid():
form.save()
else:
print(form.errors)
return render(request, 'index.html')