Imagine my surprise...oh well, here goes:
Am trying to create a module that creates a form comparing fields in two node types: A and B. What I'd like is to go through all of the nodes of type A and ensure that the field matches that of the corresponding field in the nodereferenced node B. So for each A is a B. Here's what I'm envisioning:
Tabular data representation; here's what one row would look like:
___________________________________________________________________________________________
Node Title A | Field A | 0 Choose A | _______input field | 0 Choose B | Node Title B | Field B |
___________________________________________________________________________________________
Where it says '0 Choose A' that's a radio button.
If you click on the radio button to choose A, then the value of Field B will be made to match A's Field. Likewise if you choose B, then the value for B will be inserted into Field A.
The input field would be in case the user would like to insert another value into both A and B's fields.
I'd like to have the user be able to go through a page of these, click click click the value choices, and then hit one submit button.
-------------------------
It's pretty straightforward, but it reveals a glaring weakness in how I'm conceptualizing Drupal.
I've never mixed a form with existing Drupal data.
There's part of me that was kinda nostalgic because I was going to dig into MySQL and create a table with some jurassic html skillz , then it came to the radio buttons and the input field and I stopped cold.
[sound of screeching tires on pavement]
And I realized that I'm _utterly_ clueless.
Not _completely_ clueless. I'm able to write a foreach that can grab the values from the node and its nodereferenced node and build the table. It's those darned radio buttons and the input field. How do I write those so that Drupal will create a nicely packaged array in the form values?
Any ideas?
Comments
Forms API
You use the forms API: http://api.drupal.org/api/file/developer/topics/forms_api_reference.html/6 to create each form item as an array. You can use db_query and your foreach loop and during the loop add new form elements as arrays.
--Zivtech--
Thanks Jody
Hi Jody,
Am cool with creating the arrays for the various fields mixing sql with the Form API. Do you know how to get a print_r of $form_values so I can see what I'm working with after submit?
I'm also pondering the best way to make each fieldset get named for the Node A so that the processing of form values knows which node to act on based on the return for each table row.
Thanks for your help here. I really appreciate it.
The easiest way I have found to dump $form_values.
I use the php function var_export and send it's output to the drupal messages. So if I needed to see $form_values in my validate function I would put this in:
This will give you a nice variable dump into the message queue.