0

I want to pre-populate a form field with the value from another cck field from a different content type. I have been looking into using the prepopulate module and pathauto to get the correct url, but I am not sure that these will work. I am new to drupal and kinda lost in the storm with this problem.

2 Answers 2

1

To answer the question posed in the title of this question, you could in a custom module do something along the lines of...

function MYMODULE_form_alter(&$form, $form_state, $form_id) {
  global $user;

  if ($form_id=='NODETYPE_node_form') {
     $form['field_FIELD'][0]['#default_value']['value']=$user->name;
  }

  // any other form alters you need

}

where MYMODULE is the name of your custom module, NODETYPE is the content type in question and FIELD is the field name in question without the field_ prefix. Now, whenever you are editing or creating a content type of NODETYPE, the FIELD in question will have a prefilled default value of the current user's name.

Now, if this is a different form, you'll just need to adjust the $form_id== construct to point to that form, the field in that form, etc, but the rest of the logic should be the same.

0

I'm not sure how it would apply to your situation, and I'm sorry I don't really have time to check it out completely at the moment, but you could try using Entity Reference and Entity Reference Prepopulate. By using Entity Reference, the new content type will be related back to the user in a way that can be utilized by views and many other modules. I just realized, though, that it looks like you tagged this as Drupal 6, so this solution may not work for you if you cannot move to Drupal 7.

1
  • Thanks but yes I am using d6. I am sure it would be easier in d7 but currently thats not an option.
    – Draedalus
    Jul 23, 2012 at 23:45

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.