I'm working on a hook for formit to loop over rows of fields and create multiple resources at once.
Currently while trying to figure this out I have a form containing the following table:
<table class="table responsive-table">
<thead>
<th>pagetitle</th>
<th>longtitle</th>
</thead>
<tbody>
<tr>
<td><input type="text" name="pagetitle[]" value="" /></td>
<td><input type="text" name="longtitle[]" value=""/></td>
</tr>
<tr>
<td><input type="text" name="pagetitle[]" value="" /></td>
<td><input type="text" name="longtitle[]" value=""/></td>
</tr>
</tbody>
</table>
From that I want to loop over each row to create multiple resources with the provided pagetitles & other values.
Currently my snippet looks like this:
<?php
$allFormFields = $hook->getValues();
foreach ($allFormFields as $row)
{
$doc = $modx->newObject('modResource');
$doc->set('createdby', $modx->user->get('id'));
foreach ($row as $field=>$value) {
$doc->set($field, $value);
}
$doc->save();
}
return true;
This is working in that it is creating 2 resources as it should however it is always setting my field values to blank. The log is showing that im trying to call set() on the field name "Array". I think i'm missing something obvious here to return the array key & value instead of the string "array()"
This is within my debug log:
[2014-06-10 19:46:54] (ERROR @ /modx/index.php) xPDOObject - Called set() with an invalid field name: Array
(
[0] => 0
)
[2014-06-10 19:46:54] (ERROR @ /modx/index.php) xPDOObject - Called set() with an invalid field name: Array
(
[0] => 0
[1] => 1
)
[2014-06-10 19:46:54] (ERROR @ /modx/index.php) xPDOObject - Called set() with an invalid field name: Array
(
[0] => 0
[1] => 1
[2] => 0
)