1

I need to create a form in the view (not in the edit) of a content type A. This form need to submit the data to a content type B.

I notice that node/<nodeID/edit is the "action" of the form which let you edit a node. But if I put the same action in my form on A it shows me the editing node page of B.

My form is as simple as:

<form action="xxx">
  <input type="text" name="cck_field_to_be_added_in_B" value="foobar">
</form>

Setting the xxx action isn't enough, because the FAPI requires form_id and other stuff... So, How can I build a form which is "correct" and sends the data in the rigth way?

Any idea?

----EDIT----

Using the rimian solution it worked. Heres are the dettails:

I needed the form in the view of a node created with CCK. So I have my module with two functions:

function getForm(){ 
    return drupal_get_form('buildForm');

}

function buildIngredientsForm(){
    $form[]... //bla bla bla build the form
    return $form;
}

Because I want this inside a cck content, than I can "hack" the theming system of CCK. Here explain how: http://drupal.org/node/206980

Now, whenever you wats to display your form just call print mymodule.getForm(); and the magic is done.

Regards, Segolas

Segolas
  • 575
  • 2
  • 10
  • 26

1 Answers1

1

Add another callback to the array of functions that are called when the node's edit form is submitted. You'll need to understand the basics of the form API. It's not too hard.

It goes something like this:

$form['#submit'][] = 'my_function';

Then..

function my_function() {
  //do stuff to the other node
}

See:
http://api.drupal.org/api/drupal/includes--form.inc/group/form_api
http://drupal.org/project/examples

Rimian
  • 36,864
  • 16
  • 117
  • 117
  • Thanks for your answer. I think I have to put `function my_function()` inside my module. But where exactly do I need to put `$form['#submit'][] = 'my_function';`? – Segolas May 19 '11 at 12:07
  • 1
    Yes, that's right. You'll need to make yourself a module. Your $form modification goes inside a hook_form_later (which goes in your module). It alters the form to add your extra functionality. That's the beauty of Drupal. It lets you extend existing functionality easily :) – Rimian May 20 '11 at 05:37