Variable number of fields in Drupal

The problem I'm currently working on is creating nodes in Drupal with a variable number of fields. For example I'd like to have an "officers" list for organizations they might have 1 or 5 or 50. I'd rather not hard code a certain number of fields as a maximum.

No votes yet

Comments

Aug
10
2006

add some DHTML to append new

by Anonymous

add some DHTML to append new INPUT fields to your form and have their names+IDs increment as part on array

i=i+1;

somethingsomething.innerHTML=somethingsomething.innerHTML.value+
'<input maxlength="128" name="edit[emailaddress_'+i+']" id="edit-emailaddress" size="30" value="" class="form-text" type="text">';

?

Aug
11
2006

Great idea

by Joshua Brauer

Thanks for the great tip. Here's a great page on DHTML forms I found:

http://developer.apple.com/internet/webcontent/dynamicforms.html

Aug
11
2006

Check out the embed filter

It's settings page lets you add an arbitrary number of items:
http://drupal.org/project/embedfilter

Also CCK lets you have "multiple" field types. It starts out with three, but when you fill those, you get three more.

Aug
11
2006

A great combination

by Joshua Brauer

I haven't tried embedfilter yet but I'm encouraged by the CCK option. It's still a step away from what I'm looking for but with some DHTML might be just the thing. The only drawback with CCK's multiple fields I found was that additional fields are not added until you save the record.

Aug
23
2006

Same Problem

Did you ever find a solution to this? I am attempting to do the same thing and can't get Drupal to pass me back the values in the dynamic fields. I can get around this by pulling them out of the $_POST array but am trying to avoid circumventing the API.

I posted to the Drupal forums but haven't gotten a responce.

http://drupal.org/node/80198

-T

Aug
28
2006

Mostly what is here

by Joshua Brauer

I've mostly looked at what is mentioned above. With Content Construction Kit it is possible to have multiple fields where there are as many as you want, but it requires a submit to have fields added.

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Link to Amazon products with: [amazon product_id inline|full|thumbnail|datadescriptor]. Example: [amazon 1590597559 thumbnail] or [amazon 1590597559 author]. Details are on the Amazon module handbook page.
  • Twitter-style @usersnames are linked to their Twitter account pages.
  • Twitter-style #hashtags are linked to search.twitter.com.
  • Allowed HTML tags: <a> <b> <dd> <dl> <dt> <i> <li> <ol> <u> <ul><p> <img> <table> <tr> <td><strong><em><sup><div><fn><h1><h2><h3><h4><blockquote><img style="">
  • Use [fn]...[/fn] (or <fn>...</fn>) to insert automatically numbered footnotes.
  • You may insert videos with [video:URL]
  • Lines and paragraphs break automatically.
  • Web page addresses and e-mail addresses turn into links automatically. (Better URL filter.)
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.

More information about formatting options