[Haskell-cafe] network.cgi - incomplete translation of code to
javascript
Andrew U. Frank
frank22 at geoinfo.tuwien.ac.at
Thu Aug 5 18:23:43 EDT 2010
i try to use the Network.CGI package from darcs. my testing uses the
example code from the webpage 'practical web programming in
haskell'
http://www.haskell.org/haskellwiki/Practical_web_programming_in_Haskell#Getting_user_input
specifically the example with code:
import Network.CGI
import Text.XHtml
inputForm = form << [paragraph << ("My name is " +++ textfield
"name"),
submit "" "Submit"]
greet n = paragraph << ("Hello " ++ n ++ "!")
page t b = header << thetitle << t +++ body << b
cgiMain = do mn <- getInput "name"
let x = maybe inputForm greet mn
output $ renderHtml $ page "Input example" x
main = runCGI $ handleErrors cgiMain
-- Get the value of an input variable, for example from a form.
-- If the variable has multiple values, the first one is
returned.
-- getInput :: String -> CGI (Maybe String)
this runs (runghc) and produces the output:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
><head
><title
>Input example</title
></head
><body
><form
><p
>My name is <input type="text" name="name" id="name"
/></p
><input type="submit" value="Submit"
/></form
></body
></html
>
which is clearly not producing the second part of the code,
namely output a greeting.
the same happens with the next example, using cookies, where
from two options for pattern matching only the first is include
in the javascript.
i assume that i do something wrong - but what?
any help is appreciated!
andrew
More information about the Haskell-Cafe
mailing list