Welcome to the LimeSurvey Community Forum

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

Verification of user, encryption of number entered, then transmission to survey

  • mate007
  • mate007's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 day 12 hours ago #267324 by mate007
Please help us help you and fill where relevant:
Your LimeSurvey version:
Version 5.6.17+230426
Own server or LimeSurvey hosting: LimeSurvey Community Edition
Survey theme/template: Inherit everything
==================
Unfortunately, I have a very complicated task:
briefly summarised: Verification of the user, encryption of the number entered and subsequent transmission of the encrypted number to the survey.

Problem:
I would like to check whether the user completing the survey is authorised or not. The user should verify himself. To do this, they must enter a six-digit number. The number entered is compared by the system. If the number matches, the user can start the survey.
But now it gets complicated: The six-digit number must be encrypted. The code has already been written by me and unfortunately cannot be shared here in the forum. In any case, the six-digit number is changed so that it then consists of 13 digits. I would now like to save this number in the survey.

My questions:
#How can I perform the verification query?
My solution: I use RegExp.
Example: /^(123456|234567|345678)$/
Problem: I have thousands of six-digit numbers that need to be entered. Is there a better approach for this task?
The figures are all saved in a CSV file. Can I upload the CSV file to LimeSurvey and then carry out the check?

#How can I encode the number in LimeSurvey after input and verification (now the number is expanded from 6 digits to 13 digits)?
Unfortunately, I am completely stuck here. Is there any way to change the number according to my procedure (my code)? Where can I insert my code?

#How can I submit/save the 13 digit number after encoding it in the survey?
I would have made a hidden comment field where the 13-digit number is transferred.
But again: Where can I insert the code? Do I insert the code under ‘Script’ or under ‘Source code’? If I enter the code under ‘Script’, what is the ID of the ‘Next’ button, what is the ID of the hidden field?

I know I have a lot of questions, but it's also a very complicated process that I unfortunately have to implement in exactly the same way. :/
At least the process should work in a similar way:
Verification with a six-digit number. After verification, the 6-digit number should be changed/encrypted to 13 digits. The encrypted number should then be transmitted to the survey.
I hope someone here is smart and helpful and can help me.

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 day 9 hours ago #267328 by Joffm
Hi,
how do imagine this "verification"?

I have thousands of six-digit numbers that need to be entered

So is it sufficient if the respondent enters one of these thousands of numbers?
A sophisticated way would be: "use an ajax call"
Meaning "Call a (php)-script that queries a data table with these numbers"
Or you may use the library "papaparse.js"
[url] www.papaparse.com/ [/url]
In this example the entered number is stored as default data in a question of type "short text"
Code:
<script type="text/javascript" charset="utf-8">
  $(document).on('ready pjax:complete',function() {
 
    var mynumber=$('#question{QID} input[type="text"]').val();
 
    Papa.parse("https://www.myserver.de/test.csv", {
        download: true,
        header: true,
        skipEmptyLines: true,
        complete: function(results) {
                for (i=0; i < results.data.length; i++) {
                      if (results.data[i].number==mynumber) {
 
// Do something , e.g. use your script to change from 6- to 13-digits
 
                          break;
                      }
                }
    }
     });
  });
</script>

Now you should remove the original 6-digit numer by ExpressionScript.

If there are more questions, procvide the lss export of a sample survey.

Joffm
 

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • mate007
  • mate007's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
1 day 5 hours ago #267329 by mate007
Many thanks for the answer!
I have already been able to solve a few things!

My query now consists of two ‘questions’. In the first question there is a button ‘to the verification’.
Click on it to open a window in which you can enter your data. If the verification was successful, a green tick will be displayed and you can return to the survey. Now the 7-digit number will also be inserted in the second question, in our case in a text field. You can now continue with the survey by clicking on ‘Next’. (see all four images)

I'm only stuck with two problems now:
first problem: I want the number to be inserted in the predefined text field. Unfortunately, I can only do this with ‘querySelectorAll’. Now, of course, it changes all entries to the 7-digit number. (see screenshot and code) Can I access the text field directly?
Here are the IDs of the text field:
Question overview G000Q02 (ID: 287187)
Question groups: (ID:11311)
Code:     G000Q02 : (Optional question)

And here are the IDs of the button/(first question field):
 Question overview G000Q01 (ID: 287185)
Question groups: (ID:11311)
Code:     G000Q01

Second problem:
I can't click on ‘Next’ in the survey after verification. (See screenshot)
How can I fix this?

I have now also added some screenshots and my code!
Code:
<meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">
<title></title>
<style type="text/css">/* Button */
    #verifyButton {
        background-color: #008AF2;
        color: white;
        padding: 12px 20px;
        text-align: center;
        text-decoration: none;
        display: inline-block;
        font-size: 16px;
        margin: 2px 1px;
        cursor: pointer;
        border: none;
        border-radius: 5px;
    }
 
    /*Hover-Effect */
    #verifyButton:hover {
        background-color: #0070C0;
    }
 
    /* window */
    #verificationModal {
        display: none;
        position: fixed;
        z-index: 1000;
        left: 50%;
        top: 50%;
        transform: translate(-50%, -50%);
        width: 400px;
        height: 400px;
        background-color: white;
        border: 1px solid #ccc;
        box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        padding: 20px;
        text-align: center;
    }
 
    /* Overlay */
    #overlay {
        display: none;
        position: fixed;
        z-index: 999;
        top: 0;
        left: 0;
        width: 100%;
        height: 100%;
        background-color: rgba(0, 0, 0, 0.5);
    }
 
    /* green checkmark */
    .green-checkmark {
        color: green;
        font-weight: bold;
    }
 
    /* privacy policy */
    #privacyPolicy {
        color: #0070C0;
        cursor: pointer;
    }
 
    /* close button */
    #closeButton {
        position: absolute;
        top: 10px;
        right: 10px;
        background: transparent;
        border: none;
        font-size: 20px;
        cursor: pointer;
    }
</style>
<p>Please verify yourself.</p>
 
<p><button id="verifyButton" onclick="showVerificationModal()">to the verification</button></p>
<!-- Overlay for the modal window -->
 
<div id="overlay"> </div>
<!-- modal window-->
 
<div id="verificationModal"><button id="closeButton" onclick="returnToSurvey()"></button><!-- close button -->
 
<h3>Verification</h3>
 
<div><label for="lastName">last name:</label> <input id="lastName" pattern="[A-Za-z]+" placeholder="last name" required="" type="text" /></div>
 
<div><label for="businessNumber">business number:</label> <input id="businessNumber" pattern="[0-9]{7}" placeholder="business number" required="" type="text" /></div>
 
<p>Please enter your 7-digit number.</p>
 
<div><input id="privacyCheck" required="" type="checkbox" /> <label for="privacyCheck">I accept the <span id="privacyPolicy" onclick="openPrivacyPolicy()">Privacy Policy</span></label></div>
<button onclick="verify()">Verify</button>
 
<p id="verificationStatus"> </p>
<!-- Status of verification --><!-- Return button, which is only displayed if verification is successful --><button id="returnButton" onclick="returnToSurvey()" style="display: none;">Return to the survey</button></div>
<script type="text/javascript">
    // database-some test data
    const database = {
        "Kamen": "1234567",
        "Strauss": "2345678",
        "Keil": "3456789",
        "Zeffi": "4782975"
    };
 
    // Function to display the modal window
    function showVerificationModal() {
        document.getElementById('overlay').style.display = 'block';
        document.getElementById('verificationModal').style.display = 'block';
    }
 
    // Function to open the privacy policy
    function openPrivacyPolicy() {
        window.open('https://www.privacypolicy.com', '_blank');
    }
 
    // Verification function
    function verify() {
        const lastNameInput = document.getElementById('lastName').value;
        const businessNumberInput = document.getElementById('businessNumber').value;
        const privacyChecked = document.getElementById('privacyCheck').checked;
 
        // Check whether the surname is in the database and whether the number matches
        if (privacyChecked) {
            if (database[lastNameInput] === businessNumberInput) {
                document.getElementById("verificationStatus").innerHTML = "<span class='green-checkmark'>&amp;#10004; Verifiziert!</span>";
 
                // The company number is inserted into all text fields here - want to change this!!!!!!!!!!!!!!
                const inputFields = document.querySelectorAll('input[type="text"]');
 
                inputFields.forEach(field => {
                    field.value = businessNumberInput; // Insert the number in each text field - change this !!!!!!!!!!!!!!!
                });
 
                // Show return button
                document.getElementById('returnButton').style.display = 'inline-block';
            } else {
                document.getElementById("verificationStatus").innerHTML = "<span style='color:red;'>&amp;#10008; Verification failed!</span>";
                document.getElementById('returnButton').style.display = 'none'; // Hide return button
            }
        } else {
            document.getElementById("verificationStatus").innerHTML = "<span style='color:red;'>&amp;#10008; Please accept the privacy policy!</span>";
            document.getElementById('returnButton').style.display = 'none'; // Hide return button
        }
    }
 
    // Function to return to the survey
    function returnToSurvey() {
        document.getElementById('overlay').style.display = 'none';
        document.getElementById('verificationModal').style.display = 'none';
        document.getElementById('returnButton').style.display = 'none'; // Hide return button
    }
 
    // Closes the modal window when the overlay is clicked
    document.getElementById('overlay').onclick = function () {
        returnToSurvey();
    }
</script>

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
1 day 3 hours ago #267331 by Joffm
Why don't you use the built-in features?
Why an extra button though the verification is mandatory.

Should be sufficient.
 

Here some simple javascript to verify the entries, to encrypt the number, and do other things.


If the verification fails, show a message
 

Joffm

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

  • mate007
  • mate007's Avatar Topic Author
  • Offline
  • New Member
  • New Member
More
10 hours 32 minutes ago #267343 by mate007
I have changed my verification as you mentioned
It looks like this:
image1

I am now using the inbuilt ‘Validation’ feature:
image2
How do I have to change the input validation so that it works?

If I use Javascript, it does not work:
image3

Please Log in to join the conversation.

  • Joffm
  • Joffm's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
8 hours 4 minutes ago #267346 by Joffm
Oh,
you wrote there are thousands of numbers.
How do you want to put them into your validation equation?
No, here you have to use a script.

As written before.
You have the form to enter the data.

Afterwards - in a question of type "multiple short text", where you set the entered values as default values - you do the check.
If you use the recommended Papaparse-library or an array is up to you.
Now I enter the result (valid or not) in the second subquestion and the changed number (you wrote that the number has to be changed) in the first subquestion
And here you may enter your script to "encrypt" this number.
At last I trigger the submit button to proceed.

Now appears the result form
Depending on the result eiter a SUCCESS message with a sub,it button to proceed to the survey
 

or in case of an invalid entry the FAILED message (without button to proceed)
 



And in the same group an equation to empty the original name and number.
So there is only the "encrypted" number in the dataset.
 

Joffm

again without necessity in English. Muss doch nicht sein.

Volunteers are not paid.
Not because they are worthless, but because they are priceless

Please Log in to join the conversation.

Moderators: tpartnerholch

Lime-years ahead

Online-surveys for every purse and purpose