I have been using Formidable Forms with WordPress on and off for about 3 years. I have a conventional SQL and web programming background and I have found understanding the Formidable framework difficult.
Today I had the insight that Formidable “views” are really just HTML fragments that contain data fetched by a simple SQL statement working on one table (form). They can display something small as a single unformatted field or as big a whole table. It is this intrinsic mixing of presentation and data that throws me. However, you don’t have to mix them. A view can have no HTML in it all and just return comma separated data if you want (you have to add the comma yourself).
Once I understood that these fragments can have as much or as little HTML in them as I need I realised that I could put many Formidable views onto a single page and they can all access different forms or the same form many times.
In SQL we will often join tables to get the data we want. We can’t do that in Formidable Forms because each view can only query a single table. But we can achieve a SQL join by “nesting” two Formidable Views. As the outer view loops over the each row in the first table it may call an inner view and pass a parameter to it. This parameter can be used to filter the inner view.
So the outer view might loop over,
<td>[PK]</td><td>[FK]</td><td>[display-frm-data id=x FK="[FK]"]</td>
Where [FK] is the id of the field we are passing to join on. In this example ‘FK’ will appear as parameter in the inner view and can be used to filter the second table.
This is equivalent to creating a correlated sub-query in SQL.
Select t1.PK, t1.FK, (select t2.Field1 from Table2 t2 where t2.PK = t1.FK) From Table1 t1
But in Formidable Forms we mix up the presentation and data as shown.
Parameters can also be passed to a view using a URL variable. Full details of how this works and also advice for edge cases such as dynamic fields are given here.
Pingback: Formidable views for SQL developers - how to do joins - Formidable Community