jaspervdj / digestive-functors

A general way to consume input using applicative functors
149 stars 71 forks source link

Tutorial produces bad HTML #45

Closed dubiousdavid closed 12 years ago

dubiousdavid commented 12 years ago

The form element is not embedded within the body element. The rendered output is:

<form method="POST" enctype="application/x-www-form-urlencoded" action="/"><!DOCTYPE HTML>
<html><head><title>digestive-functors tutorial</title><style type="text/css">label {width: 130px; float: left; clear: both}ul.digestive-functors-error-list { color: red; list-style-type: none; padding-left: 0px;}</style></head><body><style type="text/css">label {width: 130px; float: left; clear: both}ul.digestive-functors-error-list { color: red; list-style-type: none; padding-left: 0px;}</style><h2>Author</h2><label for="test.author.name">Name: </label><input type="text" id="test.author.name" name="test.author.name" value=""><br><label for="test.author.mail">Email address: </label><input type="text" id="test.author.mail" name="test.author.mail" value=""><br><h2>Package</h2><label for="test.package.name">Name: </label><input type="text" id="test.package.name" name="test.package.name" value=""><br><label for="test.package.version">Version: </label><input type="text" id="test.package.version" name="test.package.version" value="0.0.0.1"><br><label for="test.package.category">Category: </label><select id="test.package.category" name="test.package.category"><option value="test.package.category.0" selected="selected">Web</option><option value="test.package.category.1">Text</option><option value="test.package.category.2">Math</option></select><br><br><input type="submit" value="Submit"></body></html></form>
dubiousdavid commented 12 years ago

The following fixes the issue and removes the duplicate css inclusion.

site :: Happstack.ServerPart Happstack.Response
site = do
    Happstack.decodeBody $ Happstack.defaultBodyPolicy "/tmp" 4096 4096 4096
    r <- runForm "test" releaseForm
    case r of
        (view, Nothing) -> do
            let view' = fmap H.toHtml view
            Happstack.ok $ Happstack.toResponse  $
                template $ do
                    form view' "/" $ do
                        releaseView view'
                        H.br
                        inputSubmit "Submit"
        (_, Just release) -> Happstack.ok $ Happstack.toResponse $
            template $ do
                css
                H.h1 "Release received"
                H.p $ H.toHtml $ show release
jaspervdj commented 12 years ago

Thanks for the patch! Feel free to file a pull request next time, so you get proper credit.