We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

Creating a multi-model one-to-many form

Let's say we want to build this form:

Team: Team Name: Team Country:

Members: Member A name: Member A age: [add another member]

[REGISTER TEAM AND MEMBERS]

Add and remove members should be (I suppose) loaded via ajax. Can we build something like this in Phalcon without hacks?

Thanks in advance, mem

I think, this can be done without AJAX. Create a form with a bit of JS that can add more and more fields for members. Their names can be something like "member[0][name]", "member[0][age]", "member[1][name]" and so on - you'll have a "member" array with an array of fields in each member. When form is submitted to backend you can create team object and loop through $_POST['member'] array to create members objects.

Also you can create another actions to create members via AJAX calls and get their IDs. Then just save this IDs to team object or update them with a created team ID - it depends on your team-member models relation.