Skip to main content

The Cheeky Monkey Media Blog

A few words from the apes, monkeys, and various primates that make up the Cheeky Monkey Super Squad.

Loading CCK Fields into Your Own Drupal Forms

Have you ever wanted to add already built and setup CCK fields to a custom form in Drupal? Well I know I have and I knew I wasn't alone. After a quick search and some playing around I found a great solution posted by spinningbull as a comment on the Drupal.org forums. Here is what I'm use on one of my Forms using Form API

CCK fields to a form
  1.  // list the field names you'd like to use in your form - they will display in this order. 
  2. $fields = array('field_name_1', 'field_name_2', 'field_name_3', 'field_name_4'); 
  3. // Need to load the content modules includes to load field forms through our FAPI form
  4.  module_load_include('inc', 'content', 'includes/content.node_form');
  5.  // Loop through all the CCK fields defined in the the fields array and add them to the form array
  6.  foreach ($fields as $name) { $field = content_fields($name); 
  7. $form['#field_info'][$name] = $field; 
  8. $form += content_field_form($form, $form_state, $field); 
  9. [email protected] work through this to handle the theme, might need to go through and rip out existing theme controls } 

Hopefully this has helped you add some more reasonable items to your forms. Play nice in the jungle kids! Brian The Top Chimp.

Web Development

Would you like to know more about what we do?

View Our Services

Graphic Design Cheeky Monkey

Have a look at some our client work

View Our Work

Cheeky Monkey Discovery

Learn more about Cheeky Monkey Media

About Us

Comments