I have been struggling with a forms issue that I thought maybe someone could help answer for me.
Basically I am trying to have several drupal forms laid out in one page, with one "Save" button, which will save all of the forms on the page at once. Each form is already assumed to edit an existing node, so I do not need to worry about the case where the user is creating a new set of nodes from the forms on the page.
More specifically, one of the forms comes from the content_profile module, and the page is where the user is editing his profile. The content_profile module permits the user to create only one node of the "profile" content type. There is a set of information that I would like to expose through the profile to the user, but that set needs to be stored in a content type that allows users to create more than one node of that type. I should mention that there are fields that are only needed for the profile, and those fields are in the profile content type.
So for example, I have a "person" content type that has a field for first name and last name. This content type will be used for more than just users of the website. The "profile" content type has two fields: a URL to the user's blog, and a node reference which refers to the person node that corresponds to the user.
Let's assume that when a user signs up to the website, a profile and a person node are created and attributed to that user. (I managed to figure that part out.)
When a user edits their profile (/user/%uid/profile/profile, for those familiar with content_profile), I would like the node edit form for "profile" as well as his "person" node (determined by the node reference CCK field) to show up in the profile edit form. I only want one "Save" button. When they save their changes, both nodes are saved.
Is there some easy way to do this? Currently the form is just saving the fields relevant to the "profile" node, which is to be expected, since all of the $_POST information refers to the profile node's ID. I wanted to see if I could programmatically save the user's "person" node, but didn't know how to accurately map the data from $_POST (which gets transferred to $form_state) to the node returned by node_load(). I also tried to fake a submission and run it through the normal node submission handlers, but then the code doesn't validate because of bad form_build_id's and tokens and other esoterica that I have yet to understand.
I know that one could propose just merging the fields into the profile node, and keep the person node for those other nodes that the user creates, but there are other reasons I cannot do this. I also think that going forward it's not necessarily a sustainable way to grow the site, because if the "person" content type changes, someone has to remember to also change the "profile" content type to preserve the schema.