How do you programmatically retrieve and display the data entry form for a CCK Type from a module in Drupal 6?
I have two CCK Types (for now) with a parent-child relationship between them.
I need a page that displays the data entry forms for both types.
When the user goes to the data entry page, the parent type entry form should display until the user hits the submit button. Then the data entry form for the child type should display under it to allow the user to enter a detail record. All fields for both types need to remain editable at all times.
I was thinking that I could just do something simple like call drupal_get_form($form_id) for the CCK Data Entry Form. But that just returns an empty form (no input fields).
So the question breaks down to what is the correct method to get the form definition for a CCK content type?
Eventually, this entire form is going to be very heavily AJAX based with every field automatically updating the server as the user tabs out of the fields and the forms will be spread over a series of tabs that the user can jump back and forth between. There will also be at least 4 different CCK Content Types that get populated.
For now, I'm just trying to figure out how to display a form and will worry about the rest after that. :-)
Thanks,
Shawn.
Comments
Here is my code
Here is the code I'm using to retrieve and display a form:
The method vsdataentrytest_dataentryform() is called in a menu hook for my module.
I got the form_id by adding a hook_form_alter() method to my module that prints out the form_id of all forms on the page and then went to the create content form for my CCK Content Type.
The above code does work if I reference a non-CCK form such as the site search form. Just not with CCK forms.
Thanks,
Shawn
By looking at node_add()
By looking at node_add(), I see
$output = drupal_get_form($type .'_node_form', $node);It looks like the content create form id is
content-type_node_form, so try just append_node_formto your cck type should give you the form id?You can also get the form id from looking at the Page Source, look for
<input type="hidden" name="form_id" id="edit-YOUR FORM ID HERE" value="YOUR FORM ID HERE" />Not quite working yet... :-(
Thanks for the reply matt.
I was already using the '_node_form' suffix on my CCK type name, but I also just tried with passing in a node reference as well. But it still doesn't work.
Here is my updated code:
When I reference one of the CCK Types (either my custom type of the included 'page' type) using this approach I also receive the following error message:
Any other suggestions?
In looking through the code for drupal_get_form() in CVS, it seems to me like this should work.
Thanks,
Shawn
CCK single page data entry form
I'm trying to do more or less the same thing. I also have multiple CCK types that I'm trying to display on a single data entry page using a custom module. Each type would have a separate submit button. My CCK types do not have any sort of relationship between each other.
Eventually I want the data entry page to also display graphs of existing data right next to the data entry form.
I've tried the same mechanism that you've mentioned (drupal_get_form) and am getting the same error:
warning: call_user_func_array() [function.call-user-func-array]: First argument is expected to be a valid callback, 'node_form' was given in /Users/rkarwa/Sites/drupal/includes/form.inc on line 366.
I am considering moving away from CCK and defining my own node types and forms in a custom module to solve this problem.
I would appreciate any insight.
Thank you,
Raj
This works
After searching around a bit.. I found a comment on another article that helped me out: Thanks Lukas!. For anyone else that might need some help on how to merge multiple cck add node forms on a single page, heres the basic code that I've added to my custom module's .module file:
cck form invoke in custom module
Thanks for help, it is working fine....
Thanks for the solution
Thank you.