<div dir="ltr"><div class="gmail-post-text">

<p>Below I have an example from the <a rel="nofollow noreferrer" href="https://www.yesodweb.com/book/forms">Yesod</a> book. The form action maps to a route. How do I pass a value to that route. I know it has something to do with <code>^</code> but I can't see to make it work right.</p>

<pre class="gmail-lang-hs gmail-prettyprint gmail-prettyprinted"><code><span class="gmail-com">{-# LANGUAGE MultiParamTypeClasses #-}</span><span class="gmail-pln">
</span><span class="gmail-com">{-# LANGUAGE OverloadedStrings     #-}</span><span class="gmail-pln">
</span><span class="gmail-com">{-# LANGUAGE QuasiQuotes           #-}</span><span class="gmail-pln">
</span><span class="gmail-com">{-# LANGUAGE TemplateHaskell       #-}</span><span class="gmail-pln">
</span><span class="gmail-com">{-# LANGUAGE TypeFamilies          #-}</span><span class="gmail-pln">
</span><span class="gmail-kwd">import</span><span class="gmail-pln">           Control.Applicative
</span><span class="gmail-kwd">import</span><span class="gmail-pln">           Data.Text           </span><span class="gmail-pun">(</span><span class="gmail-pln">Text</span><span class="gmail-pun">)</span><span class="gmail-pln">
</span><span class="gmail-kwd">import</span><span class="gmail-pln">           Yesod

</span><span class="gmail-kwd">data</span><span class="gmail-pln"> App </span><span class="gmail-pun">=</span><span class="gmail-pln"> App

mkYesod </span><span class="gmail-str">"App"</span><span class="gmail-pln"> </span><span class="gmail-pun">[</span><span class="gmail-pln">parseRoutes</span><span class="gmail-pun">|</span><span class="gmail-pln">
</span><span class="gmail-pun">/</span><span class="gmail-pln"> HomeR GET
</span><span class="gmail-pun">/</span><span class="gmail-pln">input InputR GET
</span><span class="gmail-pun">|]</span></code></pre>

<p>instance Yesod App</p>

<pre class="gmail-lang-hs gmail-prettyprint gmail-prettyprinted"><code><span class="gmail-kwd">instance</span><span class="gmail-pln"> RenderMessage App FormMessage </span><span class="gmail-kwd">where</span><span class="gmail-pln">
    renderMessage </span><span class="gmail-kwd">_</span><span class="gmail-pln"> </span><span class="gmail-kwd">_</span><span class="gmail-pln"> </span><span class="gmail-pun">=</span><span class="gmail-pln"> defaultFormMessage

</span><span class="gmail-kwd">data</span><span class="gmail-pln"> Person </span><span class="gmail-pun">=</span><span class="gmail-pln"> Person
    </span><span class="gmail-pun">{</span><span class="gmail-pln"> personName </span><span class="gmail-pun">::</span><span class="gmail-pln"> Text
    </span><span class="gmail-pun">,</span><span class="gmail-pln"> personAge  </span><span class="gmail-pun">::</span><span class="gmail-pln"> Int
    </span><span class="gmail-pun">}</span><span class="gmail-pln">
    </span><span class="gmail-kwd">deriving</span><span class="gmail-pln"> Show

getHomeR </span><span class="gmail-pun">::</span><span class="gmail-pln"> Handler Html
getHomeR </span><span class="gmail-pun">=</span><span class="gmail-pln"> defaultLayout
    </span><span class="gmail-pun">[</span><span class="gmail-pln">whamlet</span><span class="gmail-pun">|</span><span class="gmail-pln">
        </span><span class="gmail-pun"><</span><span class="gmail-pln">form action</span><span class="gmail-pun">=@{</span><span class="gmail-pln">InputR</span><span class="gmail-pun">}></span><span class="gmail-pln">  </span><span class="gmail-pun"><---</span><span class="gmail-pln"> problem line </span><span class="gmail-com">-- want to do this <form action=@{InputR ^haskellValue}></span><span class="gmail-pln">
            </span><span class="gmail-pun"><</span><span class="gmail-pln">p</span><span class="gmail-pun">></span><span class="gmail-pln">
                My name is
                </span><span class="gmail-pun"><</span><span class="gmail-pln">input </span><span class="gmail-kwd">type</span><span class="gmail-pun">=</span><span class="gmail-pln">text name</span><span class="gmail-pun">=</span><span class="gmail-pln">name</span><span class="gmail-pun">></span><span class="gmail-pln">
                and I am
                </span><span class="gmail-pun"><</span><span class="gmail-pln">input </span><span class="gmail-kwd">type</span><span class="gmail-pun">=</span><span class="gmail-pln">text name</span><span class="gmail-pun">=</span><span class="gmail-pln">age</span><span class="gmail-pun">></span><span class="gmail-pln">
                years old</span><span class="gmail-pun">.</span><span class="gmail-pln">
                </span><span class="gmail-pun"><</span><span class="gmail-pln">input </span><span class="gmail-kwd">type</span><span class="gmail-pun">=</span><span class="gmail-pln">submit value</span><span class="gmail-pun">=</span><span class="gmail-str">"Introduce myself"</span><span class="gmail-pun">></span><span class="gmail-pln">
    </span><span class="gmail-pun">|]</span><span class="gmail-pln">

getInputR </span><span class="gmail-pun">::</span><span class="gmail-pln"> Text </span><span class="gmail-pun">-></span><span class="gmail-pln"> Handler Html
getInputR label </span><span class="gmail-pun">=</span><span class="gmail-pln"> </span><span class="gmail-kwd">do</span><span class="gmail-pln">
    person </span><span class="gmail-pun"><-</span><span class="gmail-pln"> runInputGet </span><span class="gmail-pun">$</span><span class="gmail-pln"> Person
                </span><span class="gmail-pun"><$></span><span class="gmail-pln"> ireq textField label
                </span><span class="gmail-pun"><*></span><span class="gmail-pln"> ireq intField </span><span class="gmail-str">"age"</span><span class="gmail-pln">
    defaultLayout </span><span class="gmail-pun">[</span><span class="gmail-pln">whamlet</span><span class="gmail-pun">|<</span><span class="gmail-pln">p</span><span class="gmail-pun">>#{</span><span class="gmail-pln">show person</span><span class="gmail-pun">}|]</span><span class="gmail-pln">

main </span><span class="gmail-pun">::</span><span class="gmail-pln"> IO </span><span class="gmail-pun">()</span><span class="gmail-pln"> 
main </span><span class="gmail-pun">=</span><span class="gmail-pln"> warp </span><span class="gmail-lit">3000</span><span class="gmail-pln"> App</span></code></pre>
    </div></div>