0

This question is related to: Custom module embedding existing node form

After dealing with returning existing node form via custom module (my_singnup module achieved with the big help of Clive) returning form has no custom field groups and custom fields.

function my_signup($node = FALSE) {
   if($node) {
     if($node->type == 'event') {
       module_load_include('inc', 'node', 'node.pages');
       global $user;
       $new_node = new stdClass;
       $new_node->type = 'signup_node_form';
       $new_node->language = LANGUAGE_NONE;
       $new_node->user = $user->uid;
       $new_node->name = (isset($user->name) ? $user->name : '');
       $form = drupal_get_form('signup_node_form', $new_node);
       return $form;
     }
   }
   return drupal_not_found();
}

signup_node_form was build via field UI (create new content type) and looks great when core node/add/signup. It has vertical tabs, validation etc.

I was expecting to get the same with mentioned code. Unfortunately it's not working. I'm getting just Drupal stuff vertical tab (Menu, Book, Version, Adress, Comments...) without my custom groups and fields.

5
  • Does the code work, now?
    – apaderno
    Mar 15, 2012 at 18:06
  • Yes, It works fine. I wish I can say TY TX here, but I don't wanna get ban :) Mar 15, 2012 at 19:57
  • I asked because you should not edit the question to include the answer. Question and answers are kept distinct. If one of the answers resolves your problem, you should accept it.
    – apaderno
    Mar 15, 2012 at 20:09
  • Oh, OK. I thought that it will be polite to show final code on top, but I do agree that it could be confusing if someone is reading all case. In Your opinion shall I paste working code as my answer or just leave buggy code and only vote for suggestion that helped me most? Mar 15, 2012 at 20:20
  • If you are not adding something to what already said in the existing answers, then adding a new answer doesn't make sense.
    – apaderno
    Mar 15, 2012 at 20:49

1 Answer 1

1

The following line in your code is wrong.

$new_node->type = 'signup_node_form'

What you are setting as node type is really the form ID, not the content type ID. If you look at the code of node_add(), you will notice the executed code is the following one.

  $types = node_type_get_types();
  $node = (object) array(
    'uid' => $user->uid,
    'name' => (isset($user->name) ? $user->name : ''),
    'type' => $type,
    'language' => LANGUAGE_NONE,
  );
  drupal_set_title(t('Create @name', array('@name' => $types[$type]->name)), PASS_THROUGH);
  $output = drupal_get_form($type . '_node_form', $node);

$type is the parameter the function gets.
If you look at the content type IDs used in Drupal, none of them contains the string "_node_form"; differently, node_add() would call drupal_get_form() passing something similar to "story_node_form_node_form" as form ID. As the modules that add fields to the node edit form check the content type of the node, it is probable they don't add fields for a content type they don't know. That is plausible, as differently it would mean that a taxonomy term field, for example, would be added to nodes for which it was not supposed to be added.

1
  • You were right - my mistake. It should be there $new_node->type = 'signup' Mar 15, 2012 at 17:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.