On Wed, 2009-01-07 at 21:28 -0800, Keyton Weissinger wrote:
> I have a form with the following fields (all required):
> - first_name
> - last_name
> - site_id
> 
> I'd like to use a template to display only the FIRST two items to the
> user for him to fill out:
> 
> <form action="{% url profiles_create_profile %}" method="POST">
> {{ form.first_name }} <br/>
> {{ form.last_name }} <br/>
> <input type="submit" value="Submit" />
> </form>
> 
> Then when it gets posted back to me I'd like to set the site_id based
> on a session variable or whatever like this (from my view):
> 
>     if request.method == 'POST':
>         my_data = {'site_id':1234}
>         my_data.update(request.POST)
>         form = form_class(data=my_data, files=request.FILES)
>         if form.is_valid():
>              process form here...
> 
> 
> My problem is that I cannot get the form to validate. It keeps telling
> me that site_id is not set.

On the surface, that look like it should work. Which makes me suspect
some important detail has been lost in the simplification.

What does the my_data dictionary look like just before you execute the
"form = ..." line (print it out)?

Also, how is form_class specified? Finally, what is the exact error
Django gives you? Print out form._errors, for example.

Maybe somewhere in there the answer will jump out. Admittedly, all the
clues may already be there and I'm just missing the obvious, but I can't
see it right now.

On a related note, is there any particular reason you need to have
site_id in the form class at all? Even if it's a model form, you could
exclude it, and add it into the model object later, couldn't you? You
might be going about this slightly backwards by trying to force in
site_id when it's not something that actually needs to be validated or
form-processed.

Regards,
Malcolm



--~--~---------~--~----~------------~-------~--~----~
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+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to