by Joshua Brauer on August 10, 2006
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.
6 Comments
add some DHTML to append new
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">';
?
Great idea
Thanks for the great tip. Here's a great page on DHTML forms I found:
http://developer.apple.com/internet/webcontent/dynamicforms.html
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.
A great combination
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.
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
Mostly what is here
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.