"Add another item" in Drupal formats other than CCK

CCK for Drupal has a convenient feature that allows one CCK field to accept multiple values ​​using the "add another element" button, which leads to an array of data in the node.

I am wondering if there is an easy way to adapt this for a form other than CCK, which I would call drupal_get_form. I would rather not invent a multi-stage wheel.

Has anyone done this?

+5
source share
3 answers

It would be nice if they included a shorter example, but this Introduction to AHAH in Drupal , as well as this post on adding dynamic form elements using AHAH should cover almost everything you need (which, unfortunately, is pretty much).

The way CCK does this (mainly in content_add_more_js()in content.node_form.inc) is a bit more confusing, as they should serve the generalization for different types of fields, as well as add some additional materials that allow the smooth Drag & Drop function. Therefore, if you do not need the latter, I would prefer not to use it as an example, since it is a bit confusing;)

+6
source

, . , , .

, drupal ( js Drupal standard js) , . , "ad-hoc" jQuery.

However, the easy part !;) The difficulty is that the functionality is achieved through AJAX, and not just by creating an additional client part of the form field. This is due to the fact that the API form must completely regenerate the form, otherwise - upon submission - additional fields that were not sent initially to the browser will simply be ignored (this is intended to prevent injection).

Hth at least a little bit! Sorry for being so concise.

+2
source

All Articles