Re: Confirm email by matching on form
On Sun, Nov 15, 2009 at 10:29 AM, Andy <asdjohnsen@gmail.com> wrote:
I have a form with an email field and email confirmation field. I
want to check the form input to make sure the two fields match. So
far I can get the error message 'Email addresses do not match.' to
display, but if they do match I am getting an error 'InterfaceError
at /order/
Error binding parameter 5 - probably unsupported type' Here is my
code:
#models
from django.db import models
from django import forms
from django.forms import ModelForm
class Customer(models.Model):
date_stamp = models.DateTimeField(auto_now_add=True)
order_number = models.PositiveIntegerField(editable=False)
first_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=40)
email = models.EmailField()
email_conf = models.EmailField(verbose_name='Confirm Email')
year_built = models.PositiveIntegerField()
period = models.PositiveIntegerField(editable=False)
direction = models.CharField(max_length=20,
choices=direction_choices)
floor_plan = models.CharField(max_length=2,
choices=floor_plan_choices)
def __unicode__(self):
return u'%s %s' % (self.first_name, self.last_name)
Not related to your problem, but storing two copies of the (verified to be the same) email address in the database seems odd. I would leave email_conf out of the model and include it only in the form.
class CustomerForm(ModelForm):
class Meta:
model = Customer
def clean_year_built(self):
year = self.cleaned_data['year_built']
if year < 1800:
raise forms.ValidationError("Please enter a year between 1800 and
2020.")
if year > 2020:
raise forms.ValidationError("Please enter a year between 1800 and
2020.")
return year
def clean_email_conf(self):
cleaned_data = self.cleaned_data
email = cleaned_data.get("email")
email_conf = cleaned_data.get("email_conf")
if email and email_conf:
if email != email_conf:
raise forms.ValidationError("Email addresses do not match.")
return cleaned_data
I'd guess the problem is here, where you are returning the entire cleaned_data array instead of just the data for the field you are cleaning.
Karen
--
You received this message because you are subscribed to the Google Groups "Django users" group.To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home