haskellyesodyesod-forms

render multiple forms in the same handler yesod


I want render 2 differents forms in the same handler but I`m not sure if possible.

the forms are:

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

I intend using this GET method

 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")

but this option not work


Solution

  • And what line of code does the error message refer to?

    Handler/TakeExam.hs:32:23: 
    Not in scope: ‘questions’ In the splice: $(widgetFile "TakeExam/answerQuestion") 
    

    I guess it is the splice in the second handler (getAnswerQuestionPR). Indeed, at the point where the file is spliced, no identifier with name questions is visible.