Hi. Well usually you would do $mapper->copyfrom('POST');
https://fatfreeframework.com/3.6/sql-mapper#copyfromThis should work just fine for the Jig and Mongo mapper.
But having an array field in the formular complicates this for the usage with a SQL table, because the mapper cannot store a raw array into a field.
So you need to split this array into multiple fields, or convert it into a json string on write and back to an array on read. Probably with a custom field setter or some load/save events:
in example:
<form>
<input name="colors[0]">
<input name="colors
[1]">
<input name="colors
[2]">
</form>
ensure that "colors" is a text field in your sql table, or has at least enough capacity to save a json string of all fields.
with events:
https://fatfreeframework.com/3.6/cursor#Eventhandlers
// on init or __construct
$encode = function($self,$pkeys=null) {
$self->set('colors',json_encode($self->get('colors')));
};
$decode = function($self,$pkeys=null) {
$self->set('colors',json_decode($self->get('colors'),true));
};
$mapper->onload($decode);
$mapper->beforesave($encode);
$mapper->afterupdate($decode); // only afterupdate here, because a load is initiated by the mapper itself after insert, which then calls the onload decoder
// on post submit in your controller
$mapper->copyfrom('POST');
$mapper->save();
// if you load the form data in your controller
$mapper->load();
$mapper->copyto('POST'); // if correctly handled in template, the data will show up again in the <input> fields
or with custom setter/getter:
class MyModel extends \DB\Mapper\SQL {
function set($key,$val) {
if ($key == 'colors') {
$val = json_encode($val);
}
return parent::set($key,$val);
}
function &get($key) {
$val = parent::get($key);
if ($key == 'colors') {
$val = json_decode($val,true);
}
return $val;
}
}
not tested but it should work somehow like this.