I want to create a master/detail form in my custom module using form api and ajax. I have three content types: CT1, CT2 and CT3. CT1 is the master, and CT2 and CT3 are details of CT1 (they have a reference field to CT1). All of them have multiple fields.
What I want is a form that shows CT1 fields (header) and two tables or grids (details) with add, edit and remove buttons for their items (multi-fields).
I have read this example module, but It recreates all the form every time you add an item, and then I lost the data that the user has completed in the other fields.
Could some one give me and example or guidelines about how to do it?I know how to create forms using form api and how to use ajax, but I need, in other words, two forms inside a form.

  • 1
    You'd be better off moving the reference field from the children to the parent - then you can use Inline entity form without the need for code – Clive Apr 16 at 18:22
  • Thanks for your suggestion. I knew this module but I'd like to do it myself. I think It couldn't be so difficult, but It seems I'm wrong. – briast Apr 19 at 9:13
  • From experience (having tried it and given up myself), it’s pretty difficult – Clive Apr 19 at 10:06
  • Ok. I'll follow your advice. But I think this is a very common use-case. A master/detail form is basic for any content type relation. Anyway, I'll give up too. – briast Apr 19 at 10:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.