WPSQT – Creating custom pages

By Iain Cambridge Monday, 18th April 2011

Wordpress-dark

Plenty of WPQST users have been requesting custom page creation documentation, so here it is! As usual, if you have any questions leave a comment and I’ll get back to you.


Step One – Creating the directory

Firstly create the custom directory. The name and required location of the custom directory can be found on the quiz or survey details page, it will be highlighted with a yellow background. It will look something like…

/var/ww/wp-content/plugins/wp-survey-and-quiz-tool/pages/custom/0/quiz-1.

You should create this directory and then copy the folders from pages/site into the custom directory. You’re custom directory should have the following layout for a quiz.

  • quiz-1/
    • site/
      • quiz/
        • finished.php
        • review.php
        • section.php
      • shared/
        • contact.php
        • custom-form.php

  • survey-1/
    • site/
      • survey/
        • finished.php
        • section.php
      • shared/
        • contact.php
        • custom-form.php


Step Two – Editing Files

Each page has different variables available to it. These variables give you great flexibility with options ranging from showing custom messages based on the percentage of the questions that have been answered right or wrong to custom styling of the survey.

Variables

quiz/
finished.php
Raw
$canAutoMarkTells us if it’s a quiz that can be automarked.
$correctAnswersThe number of questions that were answered correctly.
$totalPointsThe number of points that were availble during the quiz.
$quizNameThe name of the quiz.
$percentRightThe percentage of questions that are correct.
$emailAddressThe target email for notification messages
$timeTakenThe amount of time taken to complete the quiz in seconds.
$personNameThe name of the user who has taken the test.
$emailTrueBoolean true or false that an email is to be sent.
Sessions
$_SESSION[‘wpsqt’][$quizName][‘quiz_details’][‘display_results’]Yes or no to whether to show the results or not.
$_SESSION[‘wpsqt’][$quizName][‘quiz_details’][‘display_review’]Yes or no to the question are we to show the review.
$_SESSION[‘wpsqt’][‘result_id’]the id of the result in the MySQL database.


section.php
Raw
$quizNameThe name of the quiz.
$sectionKeyThe section key for the quiz.
$correctThe number of correct responses in last section.
$incorrectThe number of incorrect responses in the last section.
$numberOfSectionsThe number of sections in the quiz.
Sessions
$_SESSION[‘wpsqt’][$quizName][‘quiz_sections’][$sectionKey][‘questions’]Array of questions.
$_SESSION[‘wpsqt’][‘current_step’] The current step in the quiz.


review.php
Raw
$currentPointsThe current number of points.
$totalPointsThe total number of points.
Sessions
$_SESSION[‘wpsqt’]$quizName][‘quiz_sections’]Array of the sections of the quiz.



survey/
finish.php
Raw
$surveyNameThe name of the survey.
$personNameThe name of the user who has taken the test.
$emailTrueBoolean true or false that an email is to be sent.


section.php
Raw
$sectionKeyThe section key for the survey.
$numberOfSectionsThe number of sections in the survey.
Sessions
$_SESSION[‘wpsqt’][$surveyName][‘survey_sections’][$sectionKey][‘questions’]Survey questions.



shared/
Raw
$fieldsContains the custom fields for the form.


Array Layout

$_SESSION[wpsqt][$quizName][quiz_sections]

Array (
‘questions’ => Question Layout, // An Array of questions, layout can be found below
‘name’ => ‘cool section’, // Name of the section
‘type’ => ‘multiple’, // Type of the section, textarea or multiple
‘number’ => 10, // Number of questions in the section
‘orderby’ => ‘random’, // How the questions are to be ordered by
‘difficulty’ => ‘easy’, // The difficultly of the section, easy, medium or difficult.
‘stats’ => Array(
‘correct’ => 1,
‘incorrect’ => 2,
) // Correct/incorrect stats for the section.
)


$_SESSION[wpsqt][$quizName][quiz_sections][$sectionKey]['questions']

Array (
‘id’ => 1, // The question ID.
‘text’ => ‘What does Two plus Two equal?’, // The text for the questions.
‘additional’ => ‘Additional text, for the question’, // The additional text for the question.
‘type’ => ‘single’, // The type of question it is, multiple choice – single is “single”, or multiple choice – multiple is “multiple”.
‘type’ => ‘answers’ => Array(
0 => Array(
‘id’ => 1, // The Answer ID
‘text’ => ‘Answer one’ // The text for the answer
),
),
)


$_SESSION[wpsqt][$surveyName][survey_sections]

‘id’ => 1, // The section id
‘name’ => ‘Best Drink’, // The name of the survey
‘type’ => ‘’ // The type of questions in this section of the survey
‘number’ => 10 // The number of questions in this section of the survey
‘orderby’ => ‘random’ // The order of which the survey questions are to be displayed in
)


$_SESSION[wpsqt][$surveyName][survey_sections][$sectionKey]['questions']

Array (
‘id’ => 1, // The question ID.
‘text’ => ‘How awesome is IRN BRU?’, // The text for the questions.
‘type’ => ‘multiple’, // The type of question it is, multiple choice – single is “single”, or multiple choice – multiple is “multiple”.
‘type’ => ‘answers’ => Array(
0 => Array(
‘id’ => 1, // The Answer ID
‘text’ => ‘So awesome words can’t properly describe it.’ // The text for the answer
),
),
)



Required Code

Every form must have the field “wpsqt_nonce” with the value being the constant WPSQT_NONCE_CURRENT. Without this an error will be return for invalid referrer reference. As well as in a field which has the current step.

Example

<input type=”hidden” name=”wpsqt_nonce” value=”<?php echo WPSQT_NONCE_CURRENT; ?>” />
<input type=”hidden” name=”step” value=”<?php echo ( $_SESSION['wpsqt']['current_step']+1); ?>” />

Fields

Quiz
section.php
answers[$question_id][]Contains the response(s), replace the “$question_id” with the question id.

Note: The extra [] is required.

Survey
section
answers[$survey_id]Contains the response(s), replace the “$survey_id” with the survey id.

Note: The extra [] is NOT required.


Leave a comment if you need any further help with custom pages!


Posted in Plugins | 14 Comments » twitter-follow facebook-follow rss-follow

  • Kyle - EnlightenMental Productions says:

    How are the sections ordered? It doesn’t look like the sections are ordered by name, id or order entered.. wondering if it’s possible to reorder sections.

    thanks

  • Andrea says:

    Hi,

    I am trying to find the location of custom files but I am not able to find it.
    Can you give me more detail?
    I go to the “survey name”>”edit” section but here there is no path hiligthed.

    thanks,
    Andrea

  • alan says:

    I can find no “quiz or survey details page” with a custom directory listed either. Previous documentation referred to a “configure quiz” section that I also could not locate. I am running 2.4.2, so is there a paid version with these features or am I suffering from a lack of sleep? I appreciate your providing this great plugin.

  • Randy Green says:

    I’ve got the same problem as Alan and Andrea — there’s no such Details page. Also, a way to order the sections and the questions would be great! Otherwise, you have to just start over. Also a way to duplicate the survey/poll so that you can make minor variations would be good! I’d be willing to pay for a utility such as this.

  • Brian says:

    Buggy. It’s *almost* cool… You’ve only taken it part way there. Also, you should actually put some effort into responding to comments.

  • Marshall says:

    how do I change the font size on the questions? The answer font is good, but the question font is too small… I think it will cause a decrease in users.
    thanks

  • chiranjit says:

    How can I change the design and the flow of pages?

  • Rob Couty says:

    Is there anyone I can pay to do some small fixes to the plugin layout? I have installed the plugin and for the most part it works fine, but have page layout issues that I can not fix.

    So does anyone know where I can find someone who can do this work and make some money in the process?

  • Ricardo Avila says:

    How do I use these custom pages?
    I am using the parameter [wpsqt_quiz name = "Test"] to call the quiz, but only has the default template.

  • Rajkumar says:

    @Ricardo Avila

    While creating the page, on the right hand side, you will have an option to select the template which you want to use for a page..

  • Hi Ian – great plugin! It’s the best thing I’ve found so far to administer internal testing and education for my company. One question though – I’m trying to figure out the best way to implement a True/False question with a field where if the answer is false, the user can enter the correct answer. Any feedback on this matter would be greatly appreciated. Cheers!

  • Khairul says:

    How do I render out the quiz using the custom WPSQT pages? After creating those files in the directory, the quiz is still using the default template (asterisks in from of quiz questions). The only way I can come up is to replace the actual files (section.php, review.php, finished.php, etc).

    I copied & pasted the required files as instructed above and inserted the word “New” inside the header tags on (section.php) located in the newly-created ‘custom’ directory. The quiz still renders the title of the quiz section rather than “New”, which I’ve hard-coded into the custom section.php.

    @Rajkumar
    Those are wordpress theme page templates, which uses php files located in the root directory of the theme folder; not WPSQT templates used to render out the way MCQs and surveys are rendered and stylised.

  • kat says:

    How do I access the custom fields so I can show them in the results screen?

Leave a Reply

Your email address will not be published. Required fields are marked *