How to use multiple forms in one page?

250 views
Skip to first unread message

Magicloud Magiclouds

unread,
May 3, 2012, 12:20:02 PM5/3/12
to yeso...@googlegroups.com
Hi,
As the title says, how to have multiple forms work in one page?
--
竹密岂妨流水过
山高哪阻野云飞

And for G+, please use magiclouds#gmail.com.

Bryan Richter

unread,
May 3, 2012, 12:35:54 PM5/3/12
to yeso...@googlegroups.com
Maybe someone has a better idea, but I'm doing it with a manually-inserted hidden field. So my hamlet is like

<form target=@{theTarget}>
    <input type=hidden name="formId" value="form1">
    ^{form1Stuff}
...

<form target=@{theTarget}>
    <input type=hidden name="formId" value="form2">
    ^{form2Stuff}


And then my handler for @{theTarget} does something along the lines of 

targetHandler = do
    form <- runInputPost $ id <$> textField "name"
    handleForm form

handleForm :: Text -> Handler ish
handleForm "form1" = do
    ((result, widget), enctype) <- runFormPost form1
    ....
handleForm "form2" = do
    ((result, widget), enctype) <- runFormPost form2
    ....
 
If anyone has a nicer idea I would love to hear it!

Felipe Almeida Lessa

unread,
May 3, 2012, 1:22:49 PM5/3/12
to yeso...@googlegroups.com
On Thu, May 3, 2012 at 1:35 PM, Bryan Richter <bryan....@gmail.com> wrote:
> If anyone has a nicer idea I would love to hear it!

You may have different routes for each form. I don't know how well
would that fit on your app, though.

--
Felipe.

Bryan Richter

unread,
May 3, 2012, 2:30:55 PM5/3/12
to yeso...@googlegroups.com
At the time I had a really good reason for not using separate routes. I'm sure if I go back and look at it I might see things differently. :) 

TBH my whole understanding of Yesod.Form is a little shaky still. Has anyone else found it slightly difficult to wrap their heads around it? Especially wrt to client-side construction and modification of forms.

I have a newfound understanding of Applicative that might help me out when I get back to it.

-B
(wrapping up a 6-week diversion into C++ and anxious to dive back into Haskell)

Max Cantor

unread,
May 3, 2012, 12:30:01 PM5/3/12
to yeso...@googlegroups.com
for simple pages, just use the NoNonce functions for all but one of the forms, otherwise the nonce values will collide. You may still have colliding IDs, not sure. should still work but won't be "the right thing"

Max Cantor

unread,
May 3, 2012, 7:54:13 PM5/3/12
to yeso...@googlegroups.com
Oops. Are you trying to have multiple independent forms that go to the same route like:

<form action=@{RouteR}>
^{formWidget1}
<form action=@{RouteR}>
^{formWidget2}

or, multiple forms that get submitted together like:

<form action=@{RouteR}>
^{formWidget1}
^{formWidget2}

Magicloud Magiclouds

unread,
May 3, 2012, 9:52:20 PM5/3/12
to yeso...@googlegroups.com
I do not think this works. By simply using forms like this, one
problem is that submit one would trigger all non-empty check. The
other problem is the handler did not seem to work at all.

Magicloud Magiclouds

unread,
May 7, 2012, 3:28:04 AM5/7/12
to yeso...@googlegroups.com
Hi Bryan,
I have tried a few times, not succeeded.
Could you make it more clear? Thanks.
Reply all
Reply to author
Forward
0 new messages