Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

Stop Participant to continue, if entered Code is wrong

  • DarioSto
  • DarioSto's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 1 month ago #163350 by DarioSto
Hey there,

I am creating a Limesurvey which should be the second part of a long-term study.
In the first study, every participant had to enter their so-called "Mothercode". This code will enable them to see their results from that first study once again at the beginning of Study #2 (current one).

The problem I'm facing is that if the participant enter a wrong code, they should NOT be able to CONTINUE the study anymore. (Everything else - e.g. presenting the results - works just fine!)

Is it possible to do that with LS? Notice, that there are 750 entered codes in total and that I would not be pleased to create a condition for each one of them! :)

Thanks in Advance!
Dario
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago #163351 by tpartner
How are you accessing their previous response data?

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • DarioSto
  • DarioSto's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 1 month ago #163355 by DarioSto
Just by a workaround. We copied all the codenames from the 1st survey and pasted them into a question of the 2nd.

Within the expression manager (pseudo):
If Code == 'abc123' then resultA

But thats well-working :) I just need something to keep them from advancing in case the code entered is not being found in our collection of Codes.

Thanks again!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago - 6 years 1 month ago #163361 by tpartner
There may be some magic way to do it with Expression Manager but it doesn't come to me. An alternative would be to use JavaScript to hide the "Next" button and put a listener on the text input that checks the value against an array of codes.

Something like this in the question source:

Code:
<script type="text/javascript" charset="utf-8">
  $(document).ready(function() {
 
    // A list of the "Mothercodes"
    var codes = ['abc123', 'abc124', 'abc125', 'abc126'];
 
    // A function to hide/show the "Next" button
    function handleNext() {
      $('#movenextbtn, #movesubmitbtn').hide();
      if($.inArray($.trim($('#question{QID} input[type="text"]').val()), codes) >= 0) {
        $('#movenextbtn, #movesubmitbtn').show();
      }
    }
 
    // Initial state
    handleNext();
 
    // Listener on the text input
    $('#question{QID} input[type="text"]').on('keyup change', function(i) {
      handleNext();
    });
 
  });
</script>

Sample survey attached:

File Attachment:

File Name: limesurvey...2-01.lss
File Size:14 KB

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
Last edit: 6 years 1 month ago by tpartner.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago #163362 by holch
But these codes can be found in the javascript code, right? So someone with a little bit more technical background could access this.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago #163363 by tpartner
Yes.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
More
6 years 1 month ago #163368 by rigobertofernandez
Replied by rigobertofernandez on topic Stop Participant to continue, if entered Code is wrong
Hello everyone
I ask in this topic to avoid not making a new one.
I need to do something similar to this question

I need to validate if the code entered is already in the response database (lime_sourvey_xxxx) and if it finds it send an alert and restart the survey. The code is the first question in the survey.

I know I need to create a php, but I do not know anything about programming.

If someone could guide me on how to make that code and call it in my survey, I would be very grateful.
The topic has been locked.
  • holch
  • holch's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago #163372 by holch
I think creating custom php programming is a little out of the scope of this forum.

I answer at the LimeSurvey forum in my spare time, I'm not a LimeSurvey GmbH employee.
No support via private message.

The topic has been locked.
More
6 years 1 month ago #163376 by rigobertofernandez
Replied by rigobertofernandez on topic Stop Participant to continue, if entered Code is wrong
If I already have the php that makes the query to database
how to code and insert the result that query sends me to validate and show the alert message
The topic has been locked.
  • DarioSto
  • DarioSto's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
6 years 1 month ago #163392 by DarioSto
Thanks for the code, tpartner. I tried it, but it doesn't work properly though.

I understand that I have to adjust the QID Number, within the 'handleNext()' function and the 'listener', right?
Because the QID of the Input Field, where the 'mothercodes' will be typed in, has the ID number '30156', i thought it has to be something like this (which doesn't work still).

function handleNext() {
$('#movenextbtn, #movesubmitbtn').hide();
if($.inArray($.trim($('#question{30156} input[type="text"]').val()), codes) >= 0) {
$('#movenextbtn, #movesubmitbtn').show();
}
}

.....

// Listener on the text input
$('#question{30156} input[type="text"]').on('keyup change', function(i) {
handleNext();
});


Somehow the page shows no next-button at all no matter the code input. What am I doing wrong here?

thanks for your help!
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
6 years 1 month ago #163395 by tpartner
Did you try the attached survey?

Do not modify {QID}, that will automatically pipe in the correct ID.

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose