Private Functions << ^ MPForm Help pages ^ >> Field Types of MPForm
MPForm Documentation: Loops in forms
Level of difficulty: C
If you want to call a specific page of a multi page form several times you need a loop.
Example: You want to query for a "list the names, birth dates and some more data
of your children" into a form, with a separate field for each data element.
The number of children differes depending on the user who fills in the form.
Thus, you need to loop through the same page of the form until the answer to the question
"Do you have more children?" is No.
Now how can you do this with a LEPTON form?
- On the page which appears before entering the loop, you put an option field "Do you have any children" with the possible answers Yes and No.
- On the page with the loop, you put an option field "Do you have more children" with the possible answers Yes and No as last question.
- In the file private.php you find a function private_function_on_success. It is already prepared for executing a loop and all you need to do is to assign the 8 predefined variables with the correct values. You find all those values in the Backend of MPForm.
And your form loop is ready.
Now you had some hundred visitors who entered lots of data into your large multi page form, and you need to make some statistics.
The best way to offer the data in the frontend is by using the csvexport module. Take care of its security hints!
Each line in the csv file will represent the answers from one user for all pages with the same Name suffix for results table set in the backend. When creating a multi page form, it therefore makes sense to use the same suffix for each page of the form, but not for other forms! Do not change the suffix after you added fields to a form!
LEPTON knows which entries to put in which line because of the session id. So even if multiple users fill out forms at the same time, there will be no mix up of data.
But how about a looping form page, will the same fields from the first child be overwritten with data from the second child? The answer is no, because the function private_function_on_success appends some character to the session id after each loop in your code. Further children will be written into new rows. When there are 3 children, the session id might look as follows, for instance:
- form until first child: w63fr46t
- secod child: w63fr46t_
- third child: w63fr46t__
- rest of the form: w63fr46t
Matching all children of the user is no problem because the first 8 chars of the session id are constant for that user.