Forum: Ruby on Rails Opinion on Multiple forms on same page

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
18bcc556d7688096bd4daa5d72bd6c32?d=identicon&s=25 Chirantan Rajhans (chirantan)
on 2008-12-08 13:08
(Received via mailing list)
Hi,

This is probably not the best place to post this question but I wanted
to know whether using multiple form tags in the same view page should
be avoided or it is not a problem? I have heard few people saying that
one must avoid using multiple forms on the same page but I never got a
convincing explanation for the same. I need some thoughts on this.


Thanks,

Chirantan
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2008-12-08 17:18
(Received via mailing list)
On Mon, Dec 8, 2008 at 4:07 AM, Chirantan <chirantan.rajhans@gmail.com>
wrote:

> I have heard few people saying that
> one must avoid using multiple forms on the same page but I never got a
> convincing explanation for the same.

I've never heard that, and can't imagine why anyone would think it a
problem. I've certainly had projects that required multiple forms per
page.

FWIW,
--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
10f7e00c1c5c60e2173995eb16f4ffc7?d=identicon&s=25 pepe (Guest)
on 2008-12-09 18:27
(Received via mailing list)
I agree with Hassan. If you want to give your pages multiple
functionality you have to be able to use multiple forms. Just look at
Amazon, for example. After you have chosen a book/other and it's in
your cart you have a form to check out but they also offer selecting
more items. Are both things one and the same or are they run by the
same form? I hardly think so.

Pepe

On Dec 8, 11:17 am, "Hassan Schroeder" <hassan.schroe...@gmail.com>
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2008-12-10 01:25
(Received via mailing list)
POST data is not structured, so while you can use multiple forms on
the same page, there could also be namespace conflicts. The resulting
query string (in case of a conflict) could be really bizarre and prone
to subtle bugs. Not a problem when it's you writing the code or when
the page is stupid-simple. Problem if you are doing complicated stuff
and others might inherit the code.

If you want to see how Amazon implemented their form, Firebug is your
friend.

I'm not trying to convince, just offer a possible explanation :)
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2008-12-10 01:36
(Received via mailing list)
On Tue, Dec 9, 2008 at 4:24 PM, s.ross <cwdinfo@gmail.com> wrote:
>
> POST data is not structured, so while you can use multiple forms on
> the same page, there could also be namespace conflicts. The resulting
> query string (in case of a conflict) could be really bizarre and prone
> to subtle bugs.

Yes, you have to be careful with multiple forms on the page to not
have duplicate element IDs and whatnot, particularly if you're using
JavaScript. However, you can only /submit/ one form at a time, so
there should be no problem on the back end.

And I'm not sure what that second sentence means, since POST data
isn't delivered as a "query string".
Can you clarify?

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2008-12-10 02:19
(Received via mailing list)
Well, POST data is actually delivered as-if a hidden query string. So,
for a GET request, you have an HTTP QUERY_STRING and for a POST
request you have a RAW_POST_DATA. Both are functionally equivalent and
neither are scoped.

Look, it can and does work, and there's no reason to believe it will
stop any time soon. But why use multiple <form> tags when one will do?
Are they posting to different actions? Do they expect to know the
contents of fields in the other form? Should the user expect to know
the behavior of hitting enter when in one form or the other (can they
really tell they are in a different form)?

I'm not a fan, but if there's a clear argument why this is a
simplifying practice, I'm all ears.
Bee69cfed999cd13e3bff73d472a39ee?d=identicon&s=25 Hassan Schroeder (Guest)
on 2008-12-10 03:03
(Received via mailing list)
On Tue, Dec 9, 2008 at 5:18 PM, s.ross <cwdinfo@gmail.com> wrote:
>
> Well, POST data is actually delivered as-if a hidden query string. So,
> for a GET request, you have an HTTP QUERY_STRING and for a POST
> request you have a RAW_POST_DATA. Both are functionally equivalent

Mmm. Well, they both deliver data, so I suppose you could say
that. Angels, pins, tomato, tomahto, whatever :-)

> Look, it can and does work, and there's no reason to believe it will
> stop any time soon. But why use multiple <form> tags when one will do?
> Are they posting to different actions?

Of course. Why else would you do it?

> Do they expect to know the contents of fields in the other form?

Not in any example I've developed (or seen).

> Should the user expect to know
> the behavior of hitting enter when in one form or the other (can they
> really tell they are in a different form)?

If they don't understand what's going on, someone's done a crappy
job of UX design, but that applies to so many things :-)

--
Hassan Schroeder ------------------------ hassan.schroeder@gmail.com
This topic is locked and can not be replied to.