0

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.

1 Answer 1

2
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].

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you so much, just letting you know that also I had to change the input data to [model][field][0] instead of [model][0][field] thanks again, feels so good when code works.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.