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

2 Answers 2


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;
  • How I can attach a user field to a custom form? I will display that field using views in an existing view. Here is the statuses.form.inc file.
    – Umair
    May 26, 2017 at 10:10

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);

Your Answer

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

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