Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9189771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T20:18:36+00:00 2026-06-17T20:18:36+00:00

There was a method with CCK in Drupal 6 to attach a CCK field

  • 0

There was a method with CCK in Drupal 6 to attach a CCK field in our custom form, like:

$field = content_fields('field_name');  // field_name is cck field
(text_field,text_Area,image_field anything.)
$form['#field_info'][$name] = $field;
$form += content_field_form($form, $form_state, $field);

How can I achieve the same functionality in Drupal 7? I had a form and I want to use the field that I created for a content type. I went through all the files of field.module but couldn’t find anything. There are functions in it like _attach_field, field_info_Field and field_info_instance, but they can’t be rendered as a form field.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T20:18:37+00:00Added an answer on June 17, 2026 at 8:18 pm

    I like your solution of adding the entire form and unsetting. I am attacking it from another angle– create a throw-away temporary form and copy in only the field(s) you wish to preserve. Here’s what I posted at http://api.drupal.org/api/drupal/modules%21field%21field.attach.inc/function/field_attach_form/7#comment-45908:

    To add a single field off an arbitrary entity bundle (in this case, an autocomplete nodereference textfield) onto another form, create the form as a temporary form and formstate, and copy in to place that field definition. In my case, I’m working on a Commerce checkout form alter:

    function example_form_commerce_checkout_form_checkout_alter(&$form, &$form_state, $form_id) {
      $tmpform = array();
      $tmpform_state = array();
      $tmpnode = new stdClass();
      $tmpnode->type = 'card';
      // Create the temporary form/state by reference
      field_attach_form('node', $tmpnode, $tmpform, $tmpform_state);
      // Create a new fieldset on the Commerce checkout form
      $form['cart_contents']['org_ref_wrap'] = array(
        '#type' => 'fieldset',
        '#title' => t('Support Organization'),
      );
      // Place a copy of the new form field within the new fieldset
      $form['cart_contents']['org_ref_wrap'][] = $tmpform['field_card_organization'];
      // Copy over the $form_state field element as well to avoid Undefined index notices
      $form_state['field']['field_card_organization'] = $tmpform_state['field']['field_card_organization'];
    
      ..
    

    The advantage to either solution likely depends on the complexity of the “source” form (too complex means a lot of unsets with the form-insert method) and whether the source form will ever receive new fields over time (new fields will show up on your “destination” form in the form-insert method).

    Thanks for sharing your solution!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is there a method to prepopulate a certain field in a form using data
Is there a method that could tell for a string like foo bar Foo
How can i create a custom cursor in silverlight? Is there method other than
Is there a method in ruby to turn fixnum like 74239 into an array
Is there a method, like containsObject: for NSMUtableArrays to check if an object exists
Is there a method like datetime.datetime.strptime() , that accepts a string like '16:00' and
Is there a method like protected override void OnOrientationChanged(OrientationChangedEventArgs e) which works when SupportedOrientations=Portrait
is there a method to verify if a NSString haven't characters? example of string
Is there a method to return the position of the character in the JTextField.
is there a method to link specific files so that I can reference them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.