0

我遵循了 Happstack Crash Course,现在我正在尝试将不同的东西放在一起:

从“使用改革的类型安全表单处理”(http://happstack.com/docs/crashcourse/Reform.html#reform)我已经编写了这个注册表单:

register :: AcidState UserBase -> ServerPart Response
register acid = unXMLGenT $
  appTemplate "register" () $
        reform (form "/register") "register" (insertAndRenderUser acid) Nothing registerForm

insertAndRenderUser :: (Monad m) => AcidState UserBase -> User -> AppT m XML
insertAndRenderUser acid user = 
    <dl>
      <dt>lastname:</dt>    <dd><% lastName user    %></dd>
      <dt>firstname:</dt>   <dd><% firstName user   %></dd>
      <dt>email:</dt> <dd><% email user %></dd>
      <dt>birthday:</dt> <dd><% show (birthday user) %></dd>
    </dl>


registerForm :: SimpleForm User
registerForm =
    User (UserId 0)
     <$> (errorList ++> label "Last name:"  ++>  (inputText "" `transformEither` required) <++ br)
     <*> (errorList ++> label "First name:" ++> (inputText "" `transformEither` required) <++ br)
     <*> (errorList ++> label "E-mail:"     ++> (inputText "" `transformEither` required) <++ br)
     <*> (errorList ++> label "Birthday:"   ++> (inputText "" `transformEither` requireDate) <++ br)
     <*  inputSubmit "Register"

现在我想在表单成功时添加注册用户。我在酸状态(http://happstack.com/docs/crashcourse/AcidState.html#ixset)的帮助下编写了这个 UserBase

insertUser :: MonadIO m => AcidState (EventState InsertUserIntern) -> User -> m (EventResult InsertUserIntern)  
insertUser acid user = do
  update' acid (InsertUserIntern user)

这些片段单独工作,但我可以insertUser acid user在哪里插入insertAndRenderUser

我希望你能帮助 我
谢谢弗洛

4

1 回答 1

1

我自己得到了

insertAndRenderUser acid user = do
  insertUser acid user 
  appTemplate "Your Registration" () $
    <dl>
      <dt>lastname:</dt>    <dd><% lastName user    %></dd>
      <dt>firstname:</dt>   <dd><% firstName user   %></dd>
      <dt>email:</dt> <dd><% email user %></dd>
      <dt>birthday:</dt> <dd><% show (birthday user) %></dd>
    </dl>
于 2013-03-05T22:35:57.183 回答