1👍
class MyForm(Form):
first_name = forms.CharField(
max_length=128,
widget=forms.TextInput(
attrs={'placeholder': 'First Name','class': "form-control"}
),
)
last_name = forms.CharField(
max_length=128,
widget=forms.TextInput(
attrs={'placeholder': 'Last Name', 'class': "form-control"}
),
)
email = forms.EmailField(
max_length=128,
widget=forms.TextInput(
attrs={'placeholder': 'Email', 'class': "form-control"}
),
)
confirm_email = forms.EmailField(
max_length=128,
widget=forms.TextInput(
attrs={'placeholder': 'Confirm Email', n'class': "form-control"}
),
)
password = forms.CharField(
max_length=128,
widget=forms.PasswordInput(
attrs={'placeholder': 'Password', 'class': "form-control"}
),
)
confirm_password = forms.CharField(
max_length=128,
widget=forms.PasswordInput(
attrs={'placeholder': 'Confirm Password', 'class': "form-control"}
),
)
def clean_email(self):
cdata = self.cleaned_data
email = cdata['email']
confirm_email = cdata.['confirm_email']
if email and confirm_email:
if email != confirm_email:
raise forms.ValidationError("Emails do not match")
return email
def clean_confirm_email(self):
cdata = self.cleaned_data
confirm_email = cdata['confirm_email']
if not confirm_email:
raise forms.ValidationError("Please confirm your email.")
return confirm_email
def clean_password(self):
cdata = self.cleaned_data
password = cdata['password']
confirm_password = cdata['confirm_password']
if password and confirm_password:
raise forms.ValidationError("Passwords do not match.")
return password
def clean_confirm_password(self):
cdata = self.cleaned_data
confirm_password = cdata['confirm_password']
if not confirm_password:
raise forms.ValidationError("Please Confirm your Password")
return confirm_password
Source:stackexchange.com