在同一个处理程序中呈现多个表单
render multiple forms in the same handler yesod
我想在同一个处理程序中呈现 2 个不同的表单,但我不确定是否可行。
表格是:
questionForm :: ExamId -> AForm Handler Question
questionForm eid = Question
<$> areq textField (bfs (MsgQuestion)) Nothing
<*> pure eid
answerQuestionForm :: QuestionId -> AForm Handler UserAnswer
answerQuestionForm qid = UserAnswer
<$> areq textField (bfs (MsgAnswer)) Nothing
<*> pure Nothing
<*> pure qid
我打算使用这个 GET 方法
getAnswerQuestionR :: ExamId -> Handler Html
getAnswerQuestionR eid = do
mid <- maybeAuthId
questions <- runDB $ selectList [] [Desc QuestionQuestionText]
(articleWidget, enctype) <- generateFormPost $ renderBootstrap3 BootstrapBasicForm $ questionForm eid
defaultLayout $ do
$(widgetFile "TakeExam/answerQuestion")
getAnswerQuestionPR :: QuestionId -> Handler Html
getAnswerQuestionPR qid = do
uid <- requireAuthId
(widget, encoding) <- generateFormPost $ renderBootstrap3 BootstrapBasicForm $ answerQuestionForm qid
defaultLayout $ do
let actionR = ExamR
$(widgetFile "TakeExam/answerQuestion")
但是这个选项不起作用
错误消息指的是哪一行代码?
Handler/TakeExam.hs:32:23:
Not in scope: ‘questions’ In the splice: $(widgetFile "TakeExam/answerQuestion")
我猜这是第二个处理程序中的拼接 (getAnswerQuestionPR
)。的确,在拼接文件的地方,看不到名称为questions
的标识符。
我想在同一个处理程序中呈现 2 个不同的表单,但我不确定是否可行。
表格是:
questionForm :: ExamId -> AForm Handler Question
questionForm eid = Question
<$> areq textField (bfs (MsgQuestion)) Nothing
<*> pure eid
answerQuestionForm :: QuestionId -> AForm Handler UserAnswer
answerQuestionForm qid = UserAnswer
<$> areq textField (bfs (MsgAnswer)) Nothing
<*> pure Nothing
<*> pure qid
我打算使用这个 GET 方法
getAnswerQuestionR :: ExamId -> Handler Html
getAnswerQuestionR eid = do
mid <- maybeAuthId
questions <- runDB $ selectList [] [Desc QuestionQuestionText]
(articleWidget, enctype) <- generateFormPost $ renderBootstrap3 BootstrapBasicForm $ questionForm eid
defaultLayout $ do
$(widgetFile "TakeExam/answerQuestion")
getAnswerQuestionPR :: QuestionId -> Handler Html
getAnswerQuestionPR qid = do
uid <- requireAuthId
(widget, encoding) <- generateFormPost $ renderBootstrap3 BootstrapBasicForm $ answerQuestionForm qid
defaultLayout $ do
let actionR = ExamR
$(widgetFile "TakeExam/answerQuestion")
但是这个选项不起作用
错误消息指的是哪一行代码?
Handler/TakeExam.hs:32:23:
Not in scope: ‘questions’ In the splice: $(widgetFile "TakeExam/answerQuestion")
我猜这是第二个处理程序中的拼接 (getAnswerQuestionPR
)。的确,在拼接文件的地方,看不到名称为questions
的标识符。