Welcome, Guest
Username: Password: Remember me
  • Page:
  • 1
  • 2

TOPIC: using rand() and mandatory simultaneously

Re: using rand() and mandatory simultaneously 1 year 7 months ago #91994

  • TMSWhite
  • TMSWhite's Avatar
  • OFFLINE
  • LimeSurvey Team
  • Posts: 759
  • Thank you received: 82
  • Karma: 36
Denis-

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
{if(is_empty(myRand),rand(x,y),myRand)}

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 - bugs.limesurvey.org/view.php?id=5776
The administrator has disabled public write access.

Re: using rand() and mandatory simultaneously 1 year 7 months ago #92016

  • DenisChenu
  • DenisChenu's Avatar
  • OFFLINE
  • Moderator Lime
  • Posts: 6334
  • Thank you received: 818
  • Karma: 243
Hello Thomas,

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

Question:
If in RDP_ValidFunctions we set rand to:
'rand' => array('rand', '', $this->gT('Generate a random integer'), 'int rand() OR int rand(min, max)', 'http://www.php.net/manual/en/function.rand.php', 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 ....

Denis
Last Edit: 1 year 7 months ago by DenisChenu. Reason: typo: ith -> with
The administrator has disabled public write access.
  • Page:
  • 1
  • 2
Moderators: ITEd
Time to create page: 0.287 seconds
Donation Image