【发布时间】:2016-07-07 11:04:23
【问题描述】:
我有以下表格:
userForm :: UserId -> Form UserDemographics
userForm uid = renderDivs $ UserDemographics <$>
pure uid <*>
areq yearField "Year of birth" Nothing <*>
areq textField "Gender" Nothing <*>
areq countryField "Country of residence" Nothing <*>
areq boolField "Are you a computer programmer?" Nothing
在我的主页上,我使用generateFormPost $ userForm (entityKey userEnt) 制作了一个填写了UserId 的表单。但我想用AJAX 处理输入,因此单独的Handler 获取表单的结果。另一个处理程序无权访问UserId。我如何处理表格?我试过这个,它会抛出一个错误:
postDemoFormR :: Handler RepJson
postDemoFormR = do
((formData, _), _) <- runFormPost $ userForm undefined
$(logDebug) $ pack $ show formData
return $ repJson ()
我可以将userForm 的类型更改为接受Maybe UserId 而不仅仅是UserId,或者编造一个虚假的UserId 来调用runFormPost,但这两者都是黑客行为。有没有一种简单、干净的方法来做到这一点?
【问题讨论】: