Oh I see,

I've just modified my code with new import but i still have problem to
submit my form. I don t have any errors but i can't pass the
form.is_valid().
It's my first form so i don t know how to do it. Can you (again) help me ?

Here it's my forms.py :

from django import forms
from django.contrib.auth.models import User
from myApp.models import Article

class CommentForms (forms.Form):
    cf_comment = forms.CharField()
    cf_writer = User()
    cf_date = forms.DateField()
    cf_video = Article()

my template :
(...)
<form action="." method="post"> {% csrf_token %}
<input type="text" name="commentaire" />
<input type="hidden" name="user" value={{ user }} />
<input type="hidden" name="article" value={{ article }} />
<input type="hidden" name="time" value={{ now }} />
<input type="submit" value="submit" />
</form>
(...)

and my view.py :

def article(request, id):
article = Article.objects.get(id=id)
commentaires = Commentaire.objects.filter(video=video.id
).order_by("-dateComment")
#dateTime
date = datetime.datetime.now()

c = Context({
'article' : article,
'commentaires' : commentaires,
'now' : date,
})
 # preparation du formulaire de commentaire
if request.method == 'POST':
form = CommentForms(request.POST)
if form.is_valid(): #validation
cf_comment = form.cleaned_data['commentaire']
cf_date = form.cleaned_date['time']
cf_writer = form.cleaned_data['user']
cf_article = form.cleaned_date['article']
print 'IF'
else :
form = CommentForms()
print 'ELSE'


return render_to_response('myApp/article.html', c,
context_instance=RequestContext(request))


When i submit my form i can see via the python console that i m only in the
ELSE of the form.is_valid, and when i inspect via firebug what i submit in
my form i have :
commentaire test commentaire a2
csrfmiddlewaretoken c25f76451eba14ebb762bb4ed4795274
time 16
user username
vod Final

any idea ?
Great thx for your help :)

On Sat, Aug 13, 2011 at 5:53 AM, Landy Chapman <landy.chapm...@gmail.com>wrote:

> copy/paste typo, sorry.  It should have read/been:
>
> def formView(request, which_form=None):
>    if request.method == 'POST':
>        if not [1, 2].__contains__(which_form):
>            pass #  <--- iNone or nvalid form specified
>        else:
>             if which_form==1:
>                  form = form1(request.POST)
>                   redirect_url='/thanksForm1/'    #was typo
>              if which_form==2:
>                  form = form2(request.POST)
>                  redirect_url='/thanksForm2/'
>
> --
> 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.
>
>

-- 
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