On Sun, Jun 7, 2009 at 12:57 PM, zayatzz <[email protected]> wrote:

>
> I have this form:
>
> class AccountForm(forms.Form):
>        username = forms.CharField(max_length=100, help_text="Enter Username
> of your account", label="Your username")
>        email = forms.EmailField(max_length=100, help_text="Enter your
> e-mail
> address", label="Your e-mail address")
>        first_name = forms.CharField(max_length=50, help_text="Enter your
> first name(s) and/or initials", label="First name")
>        last_name = forms.CharField(max_length=50, help_text="Enter your
> last
> name", label="Last name")
>        pwd = forms.CharField(max_length=100, help_text="Enter your
> password", label="Your password")
>        pwdc = forms.CharField(max_length=100, help_text="Enter your
> password
> again", label="Your password (again)")
>        def clean(self):
>                data = self.cleaned_data
>                if len(data.get("username")) < 4:
>                        raise forms.ValidationError("Username is too short")
>                if data.get("pwd") != data.get("pwdc"):
>                        raise forms.ValidationError("Passwords do not
> match")
>
> For some reason the view does not save the stuff i get with form and i
> want to figure out why.
>

Where is it supposed to be saving to? Is it supposed to be a model form
maybe? http://docs.djangoproject.com/en/dev/topics/forms/modelforms/

Any way the real issue here is that you need to return the cleaned_data from
the clean function (or else no data comes back from the form. At the end of
the clean, put `return data`.


> Perhaps form does not validate for some reason... Where or how can i
> see those validationerrors.. how can i get them appear in view?
>

Take a look at the proper way to deal with forms in views from the
documentation here: http://docs.djangoproject.com/en/dev/topics/forms/ .
This also has examples in it.

if form.is_valid():
   # do stuff with a valid form here
else:
   print form.errors # will display the validation errors from the form

It looks like your form is valid, it just doesn't have any data because the
clean function doesn't return any thing.

I hope that helps,

Michael

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to