Here is some code to loop the forms:
<?php
//load FormIt package
$base_path = $modx->getOption('core_path') . 'components/formit/';
$modx->addPackage('formit', $base_path . 'model/');
//create a query and restrict the rows by the 'form' column
$q = $modx->newQuery('FormItForm');
$q->where(array(
'form' => 'test retriever'
));
$output = '';
$saved_forms = $modx->getCollection('FormItForm', $q);
foreach($saved_forms as $saved_form){
$values_json = $saved_form->get('values'); //read value of column 'values'
$values = json_decode($values_json, true); //convert json to an array
if ($user == $values['user']){ //test if correct user
$output .= $modx->getChunk('row_result', $values); //parse the chunk
}
}
return $output;
When you call this snippet add a user property [[!YourSnippetName? &user=`001`]]
.
In the chunk row_result you can use placeholders for all your form fields ([[+text]]
, [[+user]]
, [[+name]]
, etc.).
Like Bruno said, it’s probably a better idea to use a custom table. With this database table you always have to loop through all the rows to select the ones from a certain user.