Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'add another item' in non-CCK Drupal forms

CCK for Drupal has the handy feature of allowing a single CCK field to accept multiple values via a "add another item" button that results in an array of data in the node.

I'm wondering if there's any easy way of adapting this for a non-CCK form that I'd be calling by drupal_get_form. I'd rather not have to re-invent the wheel with multi-step form techniques.

Anyone done this?

like image 341
ceejayoz Avatar asked Dec 02 '09 23:12

ceejayoz


1 Answers

It would be nice if they had included a more reduced example, but this Introduction to AHAH in Drupal, along with this post on adding dynamic form elements using AHAH should cover pretty much all you need (which, unfortunately, is quite a bit).

The way CCK does this (mainly in content_add_more_js() in content.node_form.inc) is a bit more convoluted, as they need to cater for the generalization for different field types, as well as adding some extra stuff to allow for smooth tablesort Drag&Drop functionality. So unless you need the latter, I'd rather not use it as an example, as it gets a bit confusing ;)

like image 140
Henrik Opel Avatar answered Sep 25 '22 11:09

Henrik Opel