CCK from modification from within module code

alexeyl - April 8, 2008 - 14:36

Hi!

I need to alter CCK content type node form page. So I'd like to be able to render this form myself and surround it with my additions.
Here is how I do this:

$form = node_form(node_load($node_id));
$output .= drupal_render($form);

node id is correct and form is populated. But errors occur while rendering it:

* warning: implode() [function.implode]: Invalid arguments passed in xxx\includes\form.inc on line 548.
* warning: implode() [function.implode]: Invalid arguments passed in xxx\includes\form.inc on line 548.

What that could mean? how can I get this CCK form rendered?

Thank you!

It might help if you said

nevets - April 8, 2008 - 14:59

It might help if you said what you are trying to achieve, why/how are you trying to modify the form. Depending on your goal you probably want to theme the form and/or use hook_form_alter().

Thanks for your

alexeyl - April 8, 2008 - 17:28

Thanks for your response.

Currently I trigger this form as node/<id>/edit. But I want to output this form somewhere else inside of another page, that contains another valuable related information. Is this possible?

Also about hook_form_alter - how could I know exact id of the form from CCK? It will be just name of the type, right?

Thanks, Alex.

...

mooffie - April 9, 2008 - 06:59

$form = node_form(node_load($node_id));
$output .= drupal_render($form);

Why are you breaking the process into two steps? You're saying "and surround it with my additions", but for merely surrounding it you don't need access to $form itself.

Here's a way to do it:

$node = node_load($node_id);

$output = "my prefix";
$output .= drupal_get_form($node->type .'_node_form', $node);
$output .= "my suffix";

how could I know exact id of the form from CCK?

It's "xyz_node_form". "xyz" stands for the the node-type.

===

And if you _do_ need access to $form, do something along of:

$node = node_load($node_id);

$form_id = $node->type .'_node_form';
$form = drupal_retrieve_form($form_id, $node);
//... manipulate $form ...
drupal_process_form($form_id, $form);
$output = drupal_render_form($form_id, $form);

But errors occur while rendering it

You shouldn't pass to drupal_render() a form that wan't built yet (by drupal_process_form()), because various values need initialization.

Great! You made my day!

alexeyl - April 9, 2008 - 11:21

Great! You made my day! ;)

Thanks for your help!

 
 

Drupal is a registered trademark of Dries Buytaert.