Hello,<br><br>I&#39;m using the combination happstack + digestive-functors + web-routes + blazeHTML.<br>I&#39;m not finding any examples on the net...<br><br>I&#39;ve tried to adapt your example (thanks):<br><br><span style="font-family: courier new,monospace;">type NomicForm a = HappstackForm IO String BlazeFormHtml a</span><br style="font-family: courier new,monospace;">
<br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;"></span><span style="font-family: courier new,monospace;">demoForm :: NomicForm (Text, Text)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">demoForm =</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">    (,) &lt;$&gt; ((TDB.label &quot;greeting: &quot; ++&gt; inputNonEmpty Nothing) &lt;* br)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">        &lt;*&gt; ((TDB.label &quot;noun: &quot;     ++&gt; inputNonEmpty Nothing) &lt;* br)</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">        &lt;*  (submit &quot;submit&quot;)</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">    where</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">      br :: NomicForm ()</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">      br = view H.br</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">      -- make sure the fields are not blank, show errors in line if they are</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">      inputNonEmpty :: Maybe Text -&gt; NomicForm Text</span><br style="font-family: courier new,monospace;"><span style="font-family: courier new,monospace;">      inputNonEmpty v =</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">          (inputText v `validate` (TD.check &quot;You can not leave this field blank.&quot; (not . T.null)) &lt;++ errors)</span><br><br><br>But I&#39;ve got a problem on submit and inputTex<span style="font-family: arial,helvetica,sans-serif;">t. I don&#39;t see how they are compatible with </span><span style="font-family: courier new,monospace;"><span style="font-family: arial,helvetica,sans-serif;">HappstackForm.</span><br>
</span><span style="font-family: courier new,monospace;"><span style="font-family: arial,helvetica,sans-serif;">NomicForm a reduces to:<br><span style="font-family: courier new,monospace;">Form (ServerPartT IO) Input String BlazeFormHtml a</span></span><br style="font-family: arial,helvetica,sans-serif;">
<span style="font-family: arial,helvetica,sans-serif;"><br>whereas the type of submit is:</span><br></span><pre><span style="font-family: courier new,monospace;" class="hs-definition">submit</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-keyglyph">::</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-conid">Monad</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-varid">m</span><br style="font-family: courier new,monospace;">
<a style="font-family: courier new,monospace;" name="line-134"></a><span style="font-family: courier new,monospace;">       </span><span style="font-family: courier new,monospace;" class="hs-keyglyph">=&gt;</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-conid">String</span><span style="font-family: courier new,monospace;">                            </span><span style="font-family: courier new,monospace;" class="hs-comment">-- ^ Text on the submit button</span><br style="font-family: courier new,monospace;">
<a style="font-family: courier new,monospace;" name="line-135"></a><span style="font-family: courier new,monospace;">       </span><span style="font-family: courier new,monospace;" class="hs-keyglyph">-&gt;</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-conid">Form</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-varid">m</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-conid">String</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-varid">e</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-conid">BlazeFormHtml</span><span style="font-family: courier new,monospace;"> </span><span style="font-family: courier new,monospace;" class="hs-conid">()</span><span style="font-family: courier new,monospace;">  </span><span style="font-family: courier new,monospace;" class="hs-comment">-- ^ Submit button</span><br>
<br>Maybe I miss some instance?<br><br>BTW, I also tried to execute your exemple, but I can&#39;t install some packages.<br><br><span style="font-family: courier new,monospace;">&gt; cabal install digestive-functors-hsp</span><br style="font-family: courier new,monospace;">
<span style="font-family: courier new,monospace;">cabal: Unknown build tool trhsx</span><br><br>Whereas trhsx is in my PATH (under linux).<br></pre>You said I need the latest happstack from darcs, why?<br><br>Cheers,<br>Corentin<br>
<br><div class="gmail_quote">On Sun, Jan 9, 2011 at 8:36 PM, Jeremy Shaw <span dir="ltr">&lt;<a href="mailto:jeremy@n-heptane.com">jeremy@n-heptane.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
Hello,<br>
<br>
newRule also needs to have the type, RoutedNomicServer. The<br>
transformation of RoutedNomicServer into NomicServer is done in the<br>
handleSite function. Something like this:<br>
<br>
<br>
nomicSpec :: ServerHandle -&gt; Site Route (ServerPartT IO Response)<br>
nomicSpec sh =<br>
      Site { handleSite          = \f url -&gt; unRouteT (nomicSite sh url) f<br>
             ...<br>
<br>
main =<br>
    do ...<br>
      simpleHTTP nullConf $ siteImpl (nomicSpec sh)<br>
<br>
Or something like that -- it&#39;s hard to tell exactly what is going on<br>
in your app based on the snippets you provided.<br>
<br>
Also, I highly recommend using digestive functors instead of formlets.<br>
It is the successor to formlets. Same core idea, better implementation<br>
and actively maintained.<br>
<br>
I have attached a quick demo of using:<br>
<br>
happstack+digestive-functors+web-routes+HSP<br>
<br>
To use it you will need the latest happstack from darcs plus:<br>
<br>
 hsp<br>
 web-routes<br>
 web-routes-hsp<br>
 web-routes-happstack<br>
 web-routes-mtl<br>
 digestive-functors<br>
 digestive-functors-hsp<br>
<br>
I plan to clean up this example and document it better in the crash<br>
course for the upcoming release. Clearly things like the FormInput<br>
instance and the formPart function belong a library.<br>
<br>
let me know if you have more questions.<br>
- jeremy<br>
<br>
On Sat, Jan 8, 2011 at 6:44 PM, Corentin Dupont<br>
<div><div></div><div class="h5">&lt;<a href="mailto:corentin.dupont@gmail.com">corentin.dupont@gmail.com</a>&gt; wrote:<br>
&gt; Hello,<br>
&gt;<br>
&gt; I have difficulties mixing web-routes and forms:<br>
&gt; I have put routes in all my site, except for forms which remains with the<br>
&gt; type ServerPartT IO Response.<br>
&gt; How to make them work together?<br>
&gt;<br>
&gt; I have:<br>
&gt; type NomicServer             = ServerPartT IO<br>
&gt; type RoutedNomicServer = RouteT PlayerCommand NomicServer<br>
&gt;<br>
&gt; newRule :: ServerHandle -&gt; NomicServer Response<br>
&gt; newRule sh = do<br>
&gt;    methodM POST -- only accept a post method<br>
&gt;    mbEntry &lt;- getData -- get the data<br>
&gt;    case mbEntry of<br>
&gt;       Nothing -&gt; error $ &quot;error: newRule&quot;<br>
&gt;       Just (NewRule name text code pn) -&gt; do<br>
&gt;          html &lt;- nomicPageComm pn sh (submitRule name text code pn))<br>
&gt;          ok $ toResponse html<br>
&gt;<br>
&gt;<br>
&gt; nomicPageComm :: PlayerNumber -&gt; ServerHandle -&gt; Comm () -&gt;<br>
&gt; RoutedNomicServer Html<br>
&gt; nomicPageComm pn sh comm =<br>
&gt; (..)<br>
&gt;<br>
&gt;<br>
&gt; launchWebServer :: ServerHandle -&gt; IO ()<br>
&gt; launchWebServer sh = do<br>
&gt;    putStrLn &quot;Starting web server...\nTo connect, drive your browser to<br>
&gt; \&quot;<a href="http://localhost:8000/Login%5C" target="_blank">http://localhost:8000/Login\</a>&quot;&quot;<br>
&gt;    d &lt;- liftIO getDataDir<br>
&gt;    simpleHTTP nullConf $ mconcat [dir &quot;postLogin&quot; $ postLogin,<br>
&gt;                                   fileServe [] d,<br>
&gt;                                   dir &quot;Login&quot; $ ok $ toResponse $ loginPage,<br>
&gt;                                   dir &quot;NewRule&quot; $ newRule sh,<br>
&gt;                                   dir &quot;NewGame&quot; $ newGameWeb sh,<br>
&gt;                                   dir &quot;Nomic&quot; $ do<br>
&gt;                                      html &lt;- implSite<br>
&gt; &quot;<a href="http://localhost:8000/Nomic/" target="_blank">http://localhost:8000/Nomic/</a>&quot; &quot;&quot; (nomicSite sh)<br>
&gt;                                      ok $ toResponse html<br>
&gt;                                   ]<br>
&gt;<br>
&gt;<br>
&gt; The red line doesn&#39;t compile. I don&#39;t know how to transform a<br>
&gt; RoutedNomicServer into a NomicServer.<br>
&gt;<br>
&gt; For the future I intend to use formlets: is these some examples of programs<br>
&gt; using happstack + web-routes + formlets?<br>
&gt;<br>
&gt; Thanks,<br>
&gt; Corentin<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; On Fri, Jan 7, 2011 at 5:10 PM, Jeremy Shaw &lt;<a href="mailto:jeremy@n-heptane.com">jeremy@n-heptane.com</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt; Hello,<br>
&gt;&gt;<br>
&gt;&gt; The [(String, String)] argument is for adding query parameters.<br>
&gt;&gt;<br>
&gt;&gt; &gt; encodePathInfo [&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;] [(&quot;key&quot;,&quot;value&quot;)]<br>
&gt;&gt;<br>
&gt;&gt; &quot;foo/bar/baz?key=value&quot;<br>
&gt;&gt;<br>
&gt;&gt; Instead of showURL you would use showURLParams.<br>
&gt;&gt;<br>
&gt;&gt; hope this helps!d<br>
&gt;&gt; - jeremy<br>
&gt;&gt;<br>
&gt;&gt; On Fri, Jan 7, 2011 at 8:12 AM, Corentin Dupont<br>
&gt;&gt; &lt;<a href="mailto:corentin.dupont@gmail.com">corentin.dupont@gmail.com</a>&gt; wrote:<br>
&gt;&gt; &gt; Hello Jeremy,<br>
&gt;&gt; &gt; I&#39;m using Web routes with happstack.<br>
&gt;&gt; &gt; I&#39;m following this tutorial:<br>
&gt;&gt; &gt; <a href="http://tutorialpedia.org/tutorials/Happstack+type+safe+URLs.html" target="_blank">http://tutorialpedia.org/tutorials/Happstack+type+safe+URLs.html</a><br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; But It seems out of synch with the latest version of web-routes: 0.23.2.<br>
&gt;&gt; &gt; The haddock documentation seems out of date also:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; encodePathInfo :: [String] -&gt; [(String, String)] -&gt; String<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; For example:<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt;  encodePathInfo [\&quot;foo\&quot;, \&quot;bar\&quot;, \&quot;baz\&quot;]<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; &quot;foo/bar/baz&quot;<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; And I can&#39;t figure out what this [(String, String)] is for ;)<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Thanks,<br>
&gt;&gt; &gt;<br>
&gt;&gt; &gt; Corentin<br>
&gt;&gt; &gt;<br>
&gt;<br>
&gt;<br>
</div></div></blockquote></div><br>