using rand() and mandatory simultaneously

5 years 3 months ago #91994 by TMSWhite
TMSWhite replied the topic: using rand() and mandatory simultaneously

The EM processing flow works as follows:
(1) [Server-side] Find next set of relevant questions. So, processes the relevance equations of each group to find the next group that has at least one relevant, non-hidden question. Thus, rand() is called there
(2) [Client-side] It should not need to call the relevance equations again prior to the first page view, since the generated HTML will have the proper visibility based upon the server-side calculated relevance. This was certainly true in 1.92. There was a time when 2.0 called the EM JavaScript functions onload(), which would call rand() again. This isn't needed, but may still be happening (I haven't checked and don't have an easy way to do so).
(3) [Client-side] With each navigation change, the validation equations are processed, so rand() could be called multiple times on the page
(4) [Client-side] When Submit is pressed, there is no additional client-side validation performed, since the validation would have just occurred between the onblur event from the prior data entry field and the onfocus event arriving at the submit button
(5) [Server-side] LimeSurvey re-validates all submitted data, even though it was also validated client-side. This ensures data integrity and prevents spoofing of results.

So, as you can see, validation can be called multiple times, which is why you need the following approach for rand() (where I am assuming that you have an Equation question type called myRand and you want random values between x and y

Denis, the one thing worth checking is whether the client-side call mentioned in (2) is still happening. If so, it can be removed, which might address your concern. There is an open bug ticket about that -

Please Log in or Create an account to join the conversation.

5 years 3 months ago - 5 years 3 months ago #92016 by DenisChenu
DenisChenu replied the topic: using rand() and mandatory simultaneously
Hello Thomas,

Maybe you're right, 2 still happening, maybe javascript don't have to update rand ?

If in RDP_ValidFunctions we set rand to:
'rand' => array('rand', '', $this->gT('Generate a random integer'), 'int rand() OR int rand(min, max)', '', 0,2),
(removed rand in javascript. It will do the job ?

Oh no, js have to update rand.

Because of rand(1,QCODE) with QCODE in the same page ....


Assistance on LimeSurvey forum and LimeSurvey core development are on my free time.
I'm not a LimeSurvey GmbH member, professional service on demand (or search sondages pro).
An error happen ? Before make a new topic : remind the Debug mode .
Last Edit: 5 years 3 months ago by DenisChenu. Reason: typo: ith -> with

Please Log in or Create an account to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now
Join our Newsletter!