i'm developing a module for a site i'm working on. a site where you have to answer a series of multiple choice questions.
the way it works is that u have a question & a set of 5 answers to choose from (A-E). & you pick one by checking a checkbox (standard HTML form stuff). then the page reloads - immediately - showing the question & answer info (again) but with some extra info added. this extra info includes a tick or cross next to your answer (indicating whether you got it right or wrong), a lengthy description that appears, in a <div> element below the 5 answers (if you got the answer wrong), and some other stuff
[ this 'other stuff' = a block of info showing how your answer compared to other peoples + a small form for you to provide feedback + a 5 star rating widget for you to rate the question ]
plus, the user needs to be able to configure the quiz whenever they log on (as there's a large bank of questions, on different subjects, & users must be allowed to choose whether they want to answer questions on all categories or just some of them). but this is more like a 'landing page' for the quiz & its not this bit i'm having trouble with
where i'm having trouble is figuring out how to build these 'question pages' with drupal
i mean, if i was building it in PHP i'd just make a template page for each question. a page that'd appear - and behave - differently depending whether you were visiting it for the 1st time (ie: answering the question), or the 2nd time (getting feedback about a question you'd just answered). the fact that it'd be mixing form input functionality with content display functionality wouldn't matter
but can you do this with drupal?
i mean, i can't help thinking of each 'question' page as a node / content type. a node where some content is hidden to begin with (ie: the long description of the correct answer). but where certain functionality - specifically the form input functionality - is turned off when you're viewing the page in 'feedback mode'
but can drupal nodes contain HTML forms? forms that enable users to submit data?
i fear my ignorance is big, so if anyone can either explain why i'm thinking about this wrongly or suggest how i go about solving the problem i'd be v interested to hear ur thoughts
thanks,
david
Comments
Yes nodes can contain forms.
Yes nodes can contain forms. You call drupal_get_form() from hook_view().
Contact me to contract me for D7 -> D10/11 migrations.
so, if i have one page thats
so, if i have one page thats effectively a "multiple choice question" page, and another that appears as soon as that one is submitted (essentially a refresh) - but containing extra data like an explanation of the correct answer plus a custom block, can these both be the same node?
i mean, can a node appear in 2 different forms? both of which contain different combinations of form elements?
[ the former containing a set of radio buttons - corresponding to the "multiple choice answers" - & a submit button. the latter containing a "next question" button & a "submit feedback" button ]
& - if a node can appear in 2 different forms - then how can i differentiate which one is being shown from within hook_view? some sort of hidden field in the original form, or set #value in the submit handler perhaps?
Not really sure what you are
Not really sure what you are asking here. Sorry!
Contact me to contract me for D7 -> D10/11 migrations.
ok. i have an application
ok. i have an application that i want to convert to drupal. a multiple choice quiz
the way it works is this... (& this is the way it'll still have to work once I've drupalized it)
firstly you get a question page, with a bunch of answers to choose from. & then, when you've chosen an answer & clicked submit, you get the question & answer page. which in the existing application is just a refresh of the original page but with the addition of some extra data
this extra data includes..
> a tick or a cross next to the answer you gave (showing you whether you got it right or wrong)
> an explanation of the correct answer (which appears in a <div> tag below the questions)
NOTE: screenshots are available of these "question" pages (http://www.flickr.com/photos/53405654@N06/4932293936/sizes/l/) and "question & answer" pages (http://www.flickr.com/photos/53405654@N06/4931716633/sizes/l/). as well as a 2 minute movie that shows how the application works (http://blip.tv/file/4053310)
at the moment - & I'm not sure if I'm right about this - I'm currently conceptualizing both these pages as being different versions of the same node type
a custom "quiz question" node
in which case - if it is possible to do it this way - I guess what I'm asking is how do I differentiate, within hook_view(), which of the 2 versions of the node to build
the initial (& simple) "question" page. or the slightly more complex "question & answer" page that appears immediately afterwords
Sure you can do this. You
Sure you can do this. You call drupal_get_form() in hook_view, and then you submit the data to the database in your submission function. You load the data in hook_load(), and this data will then be available in hook_view() on the next page load. You can pass the already saved data to hook_form() and use it in your form.
Contact me to contract me for D7 -> D10/11 migrations.
cheers dude
cheers dude
Sounds to me that you wanted
Sounds to me that you wanted to build a multistep form, and the multistep form have variable "form step" that depends on the previous "step" input.
If this is the case, you shouldn't worry about content type. Basically content type is just a way to store sql data.
So if you are building a custom module, you can create a custom content type, use custom database for the field in the content type, build a custom "multi step" form, point the node/add and node/xx/edit to the custom form.
to create custom content type example :
http://api.drupal.org/api/drupal/developer--examples--node_example--node...
to build custom multistep form you need to consult drupal form api
to point the node/add or node/xxx/edit, you can consult the create custom content type example or utilize hook_form_alter and hook_menu_alter
--------------------------------------------------------------------------------------------------------
if you can use drupal why use others?
VicTheme.com
nice to know...
thanks for the replies
( hopefully when i've finished reading Packts Learning Drupal 6 Module Development & Apress's Pro Drupal Development i'll be able to make proper sense of them )