Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6360147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:36:41+00:00 2026-05-24T23:36:41+00:00

I’m trying to get the GET and the POST from the Happstack tutorial into

  • 0

I’m trying to get the GET and the POST from the Happstack tutorial into one handler function so it’s always together, which I’ve kind of achieved, but it seems ugly.

login :: ServerPart Response
login = msum [ 
    do methodM POST
       user <- look "user"
       pass <- look "pass"
       success <- query $ CheckPassword user pass
       ok $ toResponse (user ++ ", " ++ pass ++ ": " ++ (if success then "Valid" else "Invalid")),
    ok $ toResponse $ html $ do
      B.head $ do
        title "Login Form"
      B.body $ do
        form ! enctype "multipart/form-data" ! B.method "POST" $ do
             B.label "user: " >> input ! type_ "text" ! name "user" ! size "10"
             B.label "pass: " >> input ! type_ "text" ! name "pass" ! size "10"
             input ! type_ "submit" ! name "upload"]

Things I’d like to change are:

  1. Explicitly call out methodM GET rather than just have it be the fallthough.

  2. Pull out the redundant ok $ toResponse and have that only in one place.

  3. Preferably have the POST return HTML as well.

  4. Anything else that looks “off” to anyone with more experience. Any ideas?

UPDATE: figured out #1; adding do methodM GET above the ok $ toResponse $ ... works fine, but the thing for newbies like me to note is that must line up vertically, i.e., the m in methodM needs to be directly above the o in ok. Hopefully this saves someone hours of frustration.

UPDATE 2: #3 was fairly easy — just update the last line of the POST to be ok $ toResponse $ html $ do B.body $ toHtml $ user ++ ...

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T23:36:42+00:00Added an answer on May 24, 2026 at 11:36 pm

    Look up formlets (they work with Happstack) and/or digestive-functors (which work with Snap and maybe even Happstack):

    http://hackage.haskell.org/package/formlets

    http://hackage.haskell.org/package/digestive-functors

    I haven’t investigated how digestive-functors are better than formlets but it’s newer package and might be simpler than the old one.

    There are some examples

    There’s even a library in F# that compiles to JavaScript and does similar thing on client side. It allowes checking things like login availability from JS while still being written in nice formlet/functional style. It’s called WebSharper:
    WebSharper

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to understand how to use SyndicationItem to display feed which is
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
Basically, what I'm trying to create is a page of div tags, each has
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.