Processing multiple forms in same page

521 views
Skip to first unread message

Archis

unread,
Aug 23, 2008, 7:38:28 PM8/23/08
to Django users
Hi Everyone,

I am new to Django. I have page in which I have two forms. I am not
able to find a way how to differentiate between the post of the two
forms. I have separate functions to be called for post action of each
of these two forms. Can anyone provide a solution ?

Thanks

Archis

timc3

unread,
Aug 23, 2008, 9:05:41 PM8/23/08
to Django users
In your view you need to send both forms with different names and then
in the template access each form.

Like so:

t = firstForm()
p = secondForm()

objContext = RequestContext(request, {'firstform': t,
'secondform': p})
return render_to_response('formtemplate.html', objContext)

Hope that helps

Rodolfo

unread,
Aug 24, 2008, 12:51:29 AM8/24/08
to Django users
Just for curiosity, why would one have two forms in a single page?
I don't think it is possible to submit the two in a shot.

Maybe only of them is intended to be filled per access?

[]s

Rodolfo

timc3

unread,
Aug 24, 2008, 8:16:21 AM8/24/08
to Django users
Well then you just test to see what fields are pulled back, but its
fine, its possible.

I am doing it for a forum.

Daniel Roseman

unread,
Aug 24, 2008, 10:26:51 AM8/24/08
to Django users
On Aug 24, 1:51 am, Rodolfo <rhcarva...@gmail.com> wrote:
> Just for curiosity, why would one have two forms in a single page?
> I don't think it is possible to submit the two in a shot.
>
> Maybe only of them is intended to be filled per access?
>
> []s
>
> Rodolfo

You can't have two HTML forms per page, but you can have two *Django*
forms. You'd wrap them both in a single <form>...</form> element, and
Django will sort out which fields belong where according to the
prefix. So yes, you can submit them both at the same time.
--
DR.
Reply all
Reply to author
Forward
0 new messages