German German English English

 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?

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:

Matching all children of the user is no problem because the first 8 chars of the session id are constant for that user.