4

What I am looking for is not CCK flexifield or CCK Multigroup. I am trying to develop a CCK widget that allows me to enter two or more input fields per value, kind of what Doublefield does for Drupal 7. How would I develop that?

5
  • 1
    Hi, still interested? – Andy Dec 8 '11 at 13:55
  • Yes, just started a bounty to show how much I'm interested :) – Capi Etheriel Dec 8 '11 at 16:28
  • I've got a D6 CCK field that has a number of values if you'd like me to post it? – Andy Dec 8 '11 at 17:15
  • did you understand the question? I want to have more than one input per value. But it might still save them together in the database... – Capi Etheriel Dec 8 '11 at 22:46
  • Ah, no I didn't, sorry! I do have a module like that as well - just uses a submit handler to ensure the right value gets saved (if I'm correctly understanding you now). – Andy Dec 9 '11 at 10:55
1
+50

Example are taken from Phone Number CCK field. You'll need to

  1. implement hook_field_settings() to return the field data storage

    176     case 'database columns':
    177       return array(
    178         'number' => array(
    179           'type' => 'varchar',
    180           'length' => CCK_PHONE_PHONE_MAX_LENGTH,
    181           'not null' => FALSE,
    182         ),
    183         'country_codes' => array(
    184           'type' => 'varchar',
    185           'length' => CCK_PHONE_CC_MAX_LENGTH,
    186           'not null' => FALSE,
    187         ),
    188         'extension' => array(
    189           'type' => 'varchar',
    190           'length' => CCK_PHONE_EXTENSION_MAX_LENGTH,
    191           'not null' => FALSE,
    192         ),
    193       );
    
  2. implement hook_elements() to display the real input fields, where you create the FAPI inside the function cck_phone_process()

    598 function cck_phone_elements() {
    599   return array(
    600     'phone_number' => array(
    601       '#input' => TRUE,
    602       '#process' => array('cck_phone_process'),
    603       '#autocomplete_path' => FALSE,
    604     ),
    605   );
    606 }
    
3

I built something like that for drupal 7. Considering CCK moved into the drupal core in d7, I'm not really sure how much different the code would be for a cck module in d6, but maybe this module will help you

I wrote this module as I had to somehow capture phone numbers, but have them split into country code / area code and number and save them into seperate columns in the database. All other field modules I tried did not allow for this!

That way all numbers can be entered uniformly and thus presented in a uniform way - especially helpful if you use it to store and manage customer information and possibly need to export it to different applications. In my case, some users would enter phone numbers with a dash, other with a slash and others again with nothing seperating values making managing them difficult and displaying them messy.

enter image description here

Rip the code apart and modify it to suit your needs (like only 2 fields):

It's in my sandbox: http://drupal.org/sandbox/tecjam/1320886

in Git: http://drupalcode.org/sandbox/tecjam/1320886.git/tree/e7c97511506ee6e92a44656aa02d31f4e8f69727

I like to comment my code to help myself (sometimes there are more comments than code lol). So figuring out what does what and where should not be a problem at all.

You can always ask if you have any special questions.

1
  • Nice. I'll try it out with CCK and see what needs to be done. And I will hope for a CCK specific answer as well... thanks :) – Capi Etheriel Dec 8 '11 at 16:28
1

I guess I have to thank Jennifer Hodgdon (and Larry Page + Sergey Brin). There is a wonderful guide at Poplarware: http://poplarware.com/articles/cck_field_module

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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