Multiple form values in CCK - a huge problem

by domenic on Thu, 11/08/2007 - 05:33

So, if you want more than one value for a field, it's a problem.

Say you want a user to be able to enter an arbitrary number of email addresses/IM names/phone numbers/whatever on his profile. The "Allow multiple values" option in CCK is woefully adequate.

Aaron tackled this problem with aplomb (well, as far as Drupal allows) by creating a new CCK type for each field that we need to allow multiple fields on. We create a block view for it, then simply embed that view in the profile edit form.

The end result is that there's a new node created for each item (one per email address, IM name, whatever) which is kind of silly, but CCK allows no other choice at the moment. A neat side-effect, though, is that we can use AJAX on the edit page to dynamically add and delete items inside the page itself, and only require a full submit when the user changes information on the *actual* profile edit form. It's a little more involved that what I'm going into here; it's got to be themed correctly, the AJAX+Drupal issue is a whole blog post in and of itself, and so forth (if you really want the dirty details, leave a comment). It's an interesting experience -- similar to facebook style inline editing.

And such is the story of Drupal -- finding innovative solutions to the walls built around you.

Tags: CCKfieldsformsmultiples

domenic's blog  
    Delicious  Digg  Reddit  Technorati  

Comments

Yo domenic - I'd appreciate

Yo domenic - I'd appreciate seeing the dirty details on ajax with Drupal...

Interested in details

Im also looking for a similar feature for creating a custom frontpage. I want to give the editor the capability to dynamically choose how many(1,2 or 3) stories(i.e title and teaser) go in the 'Feature Stories' section and similarly for the 'Secondary Stories' section.

Therefore being able to add titles and teasers fields dynamically would be the ideal solution.

I look forward for further details on your implementation so that I can replicate it for what im trying to do.

Thanks,
Jahangir

Drupal + Ajax part I

Hi

I don't know if the comments are disabled on that post on purpose but I've been playing with the great ajax-drupal code for validating the username and I found a few doubts-details:

I think that

$form['account']['name']['#suffix']
$form['account']['name']['#attributes']

should be really:

$form['name']['#suffix']
$form['name']['#attributes']

The second thing was that if you don't have the site under "/", the GET of the ajax js won't work, I had to adapt that to point to my test site:
url: '/test/user/usernamecheck',

And the real doubt, the image of validating was gone so quickly that seemed that the ok/wrong username message was shown twice, I've had to add a PHP sleep in the demo_user_username_check function, like this:

sleep(3);

Is normal or there is something that i could do wrong?

Thanks for the tutorial!

http://www.cambrico.net

I'm responding over on

I'm responding over on http://www.workhabit.org/drupal-ajax-part-1 (and I've turned the comments on -- whoops!)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options