Check out the LimeSurvey source code on GitHub!
Welcome, Guest
Username: Password:
  • Page:
  • 1
  • 2

TOPIC: using rand() and mandatory simultaneously

using rand() and mandatory simultaneously 3 years 10 months ago #91994

  • TMSWhite
  • TMSWhite's Avatar
  • Offline
  • LimeSurvey Team
  • Posts: 758
  • Thank you received: 84
  • Karma: 37

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 -
The administrator has disabled public write access.

using rand() and mandatory simultaneously 3 years 10 months ago #92016

  • DenisChenu
  • DenisChenu's Avatar
  • Offline
  • Moderator Lime
  • Posts: 9552
  • Thank you received: 1370
  • Karma: 389
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 (Need support ?).
A bug not reported is a bug not corrected. | 2.61lts version improved | Need plugins for LimeSurvey ?
Last Edit: 3 years 10 months ago by DenisChenu. Reason: typo: ith -> with
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Time to create page: 0.244 seconds
Imprint                   Privacy policy         General Terms & Conditions         Revocation information and revocation form