using rand() and mandatory simultaneously

More
4 years 2 months ago #91994 by TMSWhite
TMSWhite replied the topic: using rand() and mandatory simultaneously
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

Please Log in to join the conversation.

More
4 years 2 months ago - 4 years 2 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 ?

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

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: 4 years 2 months ago by DenisChenu. Reason: typo: ith -> with

Please Log in to join the conversation.

Start now!

Just create your account and start using Limesurvey today.

Register now