In addition to the above, cleaning that requires two fields is best put in the forms overall clean method. This makes it a bit harder because you can't raise a validation error if you want the error to appear by the field, you have to insert it into self._errors.
Also, I have an even simpler suggestion. Don't make the user confirm their email. I'm getting fed up with seeing this on forms all over the web when it serves no purpose at all. You confirm a password because you can't read it back. You don't ask them to confirm every other field do you? </pet peeve> Peter On Nov 15, 3:42 pm, Andy <asdjohn...@gmail.com> wrote: > I should say that I am using Django 1.1.1, Python 2.5 and sqlite3. > Thanks for your help. > > On Nov 15, 9:29 am, Andy <asdjohn...@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) > > > 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 > > #views > > from django.shortcuts import render_to_response > > from django.http import HttpResponseRedirect > > from newsite.order.models import Customer, CustomerForm > > > def order(request): > > if request.method == 'POST': > > form = CustomerForm(request.POST) > > if form.is_valid(): > > form.save() > > > return HttpResponseRedirect('/order_complete/') > > else: > > form = CustomerForm() > > > return render_to_response('order.html', {'form': form}) > > > def order_complete(request): > > return render_to_response('order_complete.html') -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-us...@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=.