FORM - Populate Repeat Group with items

nbradshaw

Active Member
I am needing a way to populate a repeat group with a list of items from another table (items) on NEW (form).

So for instance (example):

items table:
item column:
printer
laptop
PC

I would like to pre-populate the repeat group with all of the rows in the items table.

Is there a solution for this?

Thanks
 
Not easily, no.

Two options:

1) Write a custom template, that rewrites default_repeatgroup.php to insert groups stocked with data, which you'd have to get by hand from the database. And stocking the data into the template is non-trivial.

2) Write a PHP form plugin, running onLoad, which does this:

Checks to see if there's a rowid.
If not, manually create a row in the main table, get the insert ID for it (rowid), then manually insert the repeat group rows, setting parent_id to the insert id.
Issue a redirect to the form, with the rowid set.

That way rather than editing a new form, you will actually be editing an existing form, with the repeat data already present.

Drawback there is, you've got an "uncompleted" row in your table, if they don't submit the form they loaded.

-- hugh
 
Iirc, on a couple of the sites I did this on, I added a hidden 'submitted' element, and a little form submission script to set that to 1 when the form is actually submitted. When I pre-create the rows, I set date_time to current time, and submitted to 0. Then I added a "garbage collection" cron job to look for rows with submitted not set to 1, and date_time > 1 hour, and delete them (and related repeat rows). That gets rid of rows where people load the form but never submit it.

It's not entirely trivial to get this going, but it's not crazy hard. Just a bit fiddly.

The last site I did this for was a "leisure center" with swimming pools, who need to do water quality tests every 3 hours. So when they load the main form, I check to see if there's a row dated for today, if not I pre-create it, and then add X repeat groups for the periodic testing. That site is still going strong.

-- hugh
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top