Confirmit dynamic questions with a twist

We know Confirmit has the option to trigger a second question (or more) based on a previous question answer, you may find this called dynamic questions.
You need to use a page object and add the questions inside then choose “triggers” on the ones you need to have them triggered.
You can define complex logic and all the other functionality such as text piping, question masking etc. can be controlled by the trigger function, so you can take advantage of all these.

That’s a pretty cool feature that allows you to chain some logic and have it working on the same page.

The downside of this is that the positioning on the screen of the second question is not always easy.
Also the logic is only evaluated when the page is submitted (when the respondent clicks the Next button), and sometime is hard to follow when the logic is complex.

I will present a different alternative for the triggers (or dynamic questions):

The set up will be the same, 2 questions on the same page, the second will be triggered by answering an option from the first question. In this example I’m using 2 multiple questions.
The second question will show up right under the option that triggers it, so its answers will nicely align under it.

In the answer label we need to use for triggering the second question will insert an empty div tag with a class, let`s call it “willTrigger”, this will help us identify which one is the one we will need to check if is clicked (checked) or not.

In my example I have this answer label to trigger the second question

Product ingredients

Here`s the script that makes all this possible, again I`m using jQuery, so don`t forget to include a reference to jQuery library in your skin:

$(function(){
    //the fieldset_q8m below is the second question fieldset name, so if your question is q11 that will change to fieldset_q11
    var trigered = $('#fieldset_q8m').parents('.questionarea');
    trigered.addClass("hidden1").removeClass('questionarea').hide();
    //add an empty tdr/td
    $('.willTrigger').closest('tr').after('<tr><td colspan=2>');
    //and populate with the hidden div
    $('.willTrigger').parents('tr').next('tr').find('td').html(trigered);
    //test input change, will also hide the error message if the answer was de-selected
    $('.willTrigger').closest('tr').find('input').change(function(){
        $(this).is(':checked')?trigered.show():trigered.hide(), $('.error_msg').hide();
    });

    // here will bind a bit of logic checking if the second question was answered
    $('form').bind('submit', function(){
        if($('.willTrigger').closest('tr').find('input').prop('checked') && !trigered.find('input:checked').length>0){
            $('.error_msg').show();
            return false;
        }
        else {
            return true;
        }
    });
});

I also created a custom style in the confirmit css styles, named “hidden1”, I’m adding to the triggered question

.hidden1{
    margin-left:10px;
}

so that its answers will be nicely aligned under, creating the impression of being part of the first question answer, like an inline answer list

Will also create some logic to check if the second question is answered before the form is submitted, so will need to create an error message like

Please select at least one ingredient

and also define this in the confirmit style list

.error_msg{
    display:none;
}

or just add the “display:none” inline


The “errorquestion” class is the default error style already defined in confrmit

The erro message div add it in the first question “instruction” tab, the script can also be placed there.

Here’s a fiddle example to see how it works, click on the “Product ingredients” and try to click next without giving any other answers there, see how the script detects the missing answers and reacts.

http://jsfiddle.net/confirmitexpert/rvPCK/embedded/result/

Do you often use the Confirmit default capabilities, or like to create everything from scratch, and have it fully customized?

Let respondent change the questionnaire language on the fly

After I published the last post I was thinking if the language example I picked was relevant or not, in fact, there’s a simpler way for an user to change the current language, in real time, without so much complex code and option changes I described in the previous post.

Here’s an easier way to let the user change the language.

Everything happens in the theme (main theme)
There`s no need to change any of the options from the “survey Settings”, link security like “unencrypted QID” or allow changing the previous answers etc, this will work with the default settings.

First we need a button or similar element,

<div class="navigationarea">
<input class="navbutton confirmit-nav" onclick="changeLanguage()" alt="" value="Switch to ^CurrentLang()=='9'?'French':'English'^" size="20" type="button"/>
</div>

As you can notice, the onclick event calls this changeLanguage() function, and its content is below:

function changeLanguage(){
    var lang= "^CurrentLang()^";
    location.href="^GetRespondentUrl()^"+String.fromCharCode(38)+(lang=="9"?"l=12":"l=9");
}

So far so good, everything works, but still there’s this screen

You have already completed parts of the questionnaire.
Press OK to continue.

Every time you click the button you get this screen (with the default settings)

To make the process smoother we will detect that page, “Internal_Continue_survey_on_entry_text”, hide its content, (please make sure you use the same wrapper class for the div that surrounds your content if not please replace it with your own), and submit the form

$(function(){
   if( $("#Internal_Continue_survey_on_entry_text").length>0 ) {
       $(".wrapper").hide();
       document.ctlform.submit();
   }
});

So let’s add everything together, please place this let’s say at the end of your main theme, right after the navigation component. In the layout tab use the code editor, not the WYSIWYG.
Don’t forget to include the jQuery library in the external js
“External Javascript Url” like https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js

All added together below


<div class="navigationarea">
<input class="navbutton confirmit-nav" onclick="changeLanguage()" alt="" value="Switch to ^CurrentLang()=='9'?'French':'English'^" size="20" type="button"/>
</div>

Confirmit surveys jQuery lightBox ready

This is something that will make both your clients and respondents happy.

There shouldn’t be too much to say about how this works, I’m sure you already know.

It’s good to have something like this in surveys, where you have to display lots of images, and for a great user experience, just make sure the thumbnails have the same size (height and width).

To make it work, download the plugin, here’s one link http://leandrovieira.com/projects/jquery/lightbox/

Add the lines below inside your theme

 
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script>
<link rel="stylesheet" type="text/css" href="css/jquery.lightbox-0.5.css" media="screen" />
<script type="text/javascript">$(function() {$('[rel*=lightbox]').lightBox();});</script>

And use it like below. You can have it working in the question text, or in the answers.

 
<a href="image1.jpg" rel="lightbox" title="Some title here"><img src="thumb_image1.jpg" width="60" height="60" alt="" border="0" /></a>

Redirect to a different project or web application, and capture data back

Here is a technique I used in various projects I was working on, where I had to link to a different project, modules or third party applications, pass some data and collect other data back.

Start by creating a script node with the content below:

var applicationUrl="the_application_url";
var theRespondentUrl=HttpUtility.UrlEncode(GetRespondentUrl()+"&__qid=backFromApp");
//or since Confirmit15 GetRespondentUrl("backFromApp");
var x,y="";//here some variables and values, you can take those from other questions as you wish
var additionalVariables="&x="+x+"&y="+y;
Redirect(applicationUrl+"?linkBack="+theRespondentUrl+additionalVariables,true);

Next, add an info question, with the ID backFromApp, and here is the place where we expect to have the respondent returned,

<input type="hidden" name="dataCaptured" id="dataCaptured">
<script type="text/javascript">
function getUrlVariables(){ 
  var variablesUrl = [], variableNameValue; 
   var variablePair = window.location.href.slice(window.location.href.indexOf('?') + 1).split('&'); 
    for(var i = 0; i < variablePair.length; i++)    { 
       variableNameValue = variablePair[i].split('='); 
       variablesUrl.push(variableNameValue[0]);  
       variablesUrl[variableNameValue[0]] = variableNameValue[1]; 
   }
  return variablesUrl;
}

document.ctlform.dataCaptured.value=getUrlVariables()[ 'oneInParticular'];//store data in hidden form element, dataCaptured
document.ctlform.submit();//go to the next question
</script>

Please make sure you use the right variable name, since it’s case sensitive.

A script node follows the info question above, and stores the data back in Confirmit, let’s say you have an open end with the id “dataCaptured”

f('dataCaptured').set(Request('dataCaptured'));

On the other end (in the external app, or even Confirmit project) you only need to capture the link, store it, append the data and redirect the respondent back.

Treat or Prevent?

It’s a pretty simple question, and most of you can definitely say to prevent is better.

If it’s so obvious preventing is better, I’m then wondering why Confirmit (and other survey software too..) isn’t.
I see internal scripts, masking, validation, throwing errors, etc. everything to make sure there’s no way a respondent will answer wrong, wrong meaning not following our instructions, the humongous text we insert to make sure he will finally get how he’s supposed to answer the question.

But.. Nothing really to prevent it, right? Confirmit has some tries lately, and this means is up to us to find different ways.

What we can do? There`s plenty of room for improvement, means that in the following posts, we will be focusing on how to improve the … of course, the user experience

Support “limited(Email invitation)” and “open survey” in Confirmit and store data in the same projectID

One of the pain points when starting with Confirmit is that you don’t know what all the options means

Lets start with the “web options”:

If you have a request to support a limited (or Email invitation survey that requires an uploaded respondent list with email field) and an open survey (Gives you a general link to the interview, which e.g. can be used as hyperlink on your website) you’ll see the options are excluding each other, so you can’t have both in the same time.
Wondering if this is possible? Well, it is:

Leave the survey with the option “open survey” checked.
*Script your survey as usually.
*Compile, then import the sample file, so that you can invite people in. (In the sample file, you will need at least their email address, if you plan to use Confirmit to send the invites, of course.)
And that’s everything.

Now, because it’s public and other people could get in as well we need to add some sort of control and in the same time some tracking.

First will do some conventions:
Let’s say we need to get people in from some websites, from a banner with the survey link attached
the url will look like this
theSurveyURL?source=1 (for the first website or banner)
theSurveyURL?source=2 (for the second website or second banner) and so on..

Right where the survey starts, we’ll capture the source value and store it as explained below
So we need to create a script node with these simple lines:

var source=Request("source");
/*will only store it if it's a number
1 for website 1 or first banner
2 for website 1 or second banner
...etc
*/
if (!isNaN(source))
f('source').set(source);

source is a hidden single question type
banner1 1
banner2 2
website2 3
etc

We’ve only covered the “tracking” part so far. We also need to add at least some control, so the next Confirmit node is a condition node

!f('q1').toBoolean() && (GetRespondentValue('email')=="" || GetRespondentValue('email')==null)

this means, there’s no source or source is not a number, and the respondent is not one of our sample folks who came using their Confirmit unique links
if the condition is true, send him to a block, with an info page saying “this survey is no longer available”, or something else more friendlier… and close the interview with a status screened.