Reputation: 835
Basically I've made a form in Cakephp 2.1 with a jQuery button that appends an input field and adds a count to each of the newly created input like so:
<input type="text" name="data[foo][link]" /> // Original input
<input type="text" name="data[foo][1][link]" /> // Appended inputs
<input type="text" name="data[foo][2][link]" />
<input type="text" name="data[foo][3][link]" />
My question is if it's possible to get all of these inputs to save into the same [foo][link] table in the database (preferably as an array)?
Thanks heaps.
Upvotes: 0
Views: 339
Reputation: 25698
public beforeSave() {
if (isset($this->data['Foo'])) {
$this->data['YourModel']['realField'] = serialize($this->data['Foo']);
}
return true;
}
In the afterFind() you revert that by using unserialize();
data[foo][link] Should be data[foo][0][link].
Upvotes: 2