Drupal Answers is a question and answer site for Drupal developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to use existing content type field in my own custom form. Like In content type, we can use existing field.

share|improve this question
up vote 5 down vote accepted

In Drupal 7 you can use field_attach_form

function hook_form($form, &$form_state) {
  $form['fname'] = array(
    '#type' => 'textfield',
    '#title' => t('first name'),
  $form['lname'] = array(
    '#type' => 'textfield',
    '#title' => t('last name'),
  //attaching existing content type fields
  $node = new stdClass();
  $node->type = 'article'; //content type
  field_attach_form('node', $node, $form, $form_state); //it will attach all the fields
  unset($form['body']); //unset other fields like this.
  return $form;
share|improve this answer

You should consider using field_attach_form function.

An example use of this in user.module is as follows.

field_attach_form('user', $form['#user'], $form, $form_state, $langcode);
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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