WP Survey And Quiz Tool
Add new type of question (4 posts)

  1. Sziro
    Posted 3 years ago #


    Can you help me finding the spots in the WP Survey And Quiz Tool's code, where can I add my code?

    I would like to add new types of questions, to suite my needs. The idea is to use JS, construct the answer as a string, set it back to a simple text type input and than store it into database with this plugin.
    For example JS datepicker feeds back a date to a text input in the form, like '2012-12-22'. For this, I need the system to generate
    <input type="text" class="datepicker" name="whatever-the-plugin-uses"/>
    for specific questions. Where can I add my code, so in the admin, I can choose a new question type that does this custom behavior.

    The same question, but with a hidden answer. For example there is a JS that let's the user add children with their names. The plugin should save a simple string (constructed by the JS for example 'Jack;Jill' or '') to the DB, but not show an input text field.

    I would like to have a likert type question, with the scales of -5 to +5. Where can I add my code to have this new subtype of likert question?

    Thanks for the help,


  2. Sziro
    Posted 3 years ago #

    The answer for 1 is, if someone needs it:

    - Duplicate, rename the \lib\Wpsqt\Question\Freetext.php to Datepick.php .
    Change class name to Wpsqt_Question_Datepick, id to datepick.
    Change form view to pages/admin/forms/question.date.php
    Change display view to pages/site/questions/date.php

    - Create this mentioned two files to the appropiate directory. In question.date.php change the form to sub_form_datepick. On date.php change the textarea to
    <input type="text" class="datepicker" name="answers[<?php echo $questionKey; ?>][]"><?php if (!empty($givenAnswer)) { echo stripcslashes(current($givenAnswer)); }?></input>

    - Find the header file of your theme (or you can add to date.php), insert

        $(function() {
            $( ".datepicker" ).datepicker({
                changeMonth: true,
                changeYear: true,
                dateFormat: 'yy-mm-dd'

    - In \lib\Wpsqt\System.php add 'Date Pick' => 'Textbox with date chooser.' to the array at function getSurveyQuestionTypes(). (If you whant to add the type to the survey. There is a list for the quiz too.)

    - In \pages\admin\surveys\question.create.php add
    <option value="datepick"<?php if ( !isset($questionType) || $questionType == 'datepick' ){?> selected="selected"<?php }?>>Date Picker</option>
    to the <select name="type" id="type"> list.

    - This will be a clone to the freetext answer. If you would like to customize it further, modify \js\generic.js to have a custom form, and create it.

  3. klappradla
    Posted 3 years ago #

    That's exactly what I need - thanks a lot!
    But how did you get the results of your new questiontype?

  4. klappradla
    Posted 3 years ago #

    Ok, I solved it with my own workaround: just saved the answers as if it were a freetext-question.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • WP Survey And Quiz Tool
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic