(I've been reading back through the issue queue and through the forums in hopes of figuring this out, and, while I've seen several posts noting similar difficulties, I haven't yet found one that had arrived at a solution, so thought I'd post this in hopes of getting a more definitive answer for future searchers.)

I've written a bookmarklet to grab Dublin Core metadata values from XML files from another site and pass them into a node create form using the Prepopulate module. (It's a pretty involved script, so the bookmarklet is just a stub to load an external .js file.) Everything's working great, except that I'm running into problems getting a multivalue CCK text field to populate correctly.

I've succeeded in getting the script to output the right URL. My javascript skills are pretty basic, so... well, let's just say I learned a lot in the process, but the URL takes the proper form. The relevant section looking like this:

... &edit[field_attrib_author][0][value]=First Author's Name&edit[field_attrib_author][1][value]=Second Author's Name ...

The problem is that only the first value in the multivalue (i.e. [0]) CCK field gets filled in. The others don't work. Strangely, if I click "Preview" on the node create form, the second value (i.e. [1]) will then appear in the node edit form, and subsequent values appear successively each time I preview the node. (All other fields populate correctly, but then none of them are multiple value fields.)

I'm wondering if this comment would address this problem, but I'm afraid I don't quite understand enough of what was going on in that thread to know for sure.

I don't know if this is something I'm not understanding about Prepopulate or if it's something I'm not understanding about CCK. Any help anybody could provide, though, would be much appreciated.

Comments

benjamin.pauley’s picture

I haven't been able to find a real answer to the question I posed, but, in the event anybody else stumbles across this in a search, I wanted to pass on a workaround. It's not a perfect solution, but it might do the trick for somebody.

It seems as though the multiple-value cck fields can't be populated past the first value from URLs (that is, the first value—[field_name][0][value] will populate, but [field_name][1][value] and following won't).

What I ended up doing was assembling multiple values into a comma-separated string and passing that string to [field_name][0][value]. I then use an unlimited value Computed Field to explode that string at the commas and create an array that can fill an unlimited number of values. (A snippet for doing so can be found here. That example is labeled Drupal 5.x, but it seems to work for Drupal 6.x, too.)

The resulting values aren't directly editable, unfortunately. But you can keep the field that received the comma-separated string visible on the node edit form; any new values added to that comma-separated list will turn up when the node is saved again.

It's not necessarily a great solution, so if anybody can provide a better guide to populating multiple-value cck fields from URLs using Prepopulate, I'd welcome the information.

benklocek’s picture

Interested in this functionality also.

ISPTraderChris’s picture

Subscribing.

Would be nice to specify open bracket notation '[]' to signify a NEW multi-value set -- this shouldn't be too hard to do. I'll take a look if I find some time.

totoro’s picture

Component: Documentation » Code
Category: support » feature

Had a similar problem when trying to prepopulate multiple values, specifically with nodereferences.
Went through the code to find that the overall prepopulate approach seems not to be complatible with adding more stuff to a form, only to modify what already exists there.

My workaround was setting a default value php in the field configuration, just like this one:

$empty_default_values = array(array('nid'=>0));
      if(!empty($_REQUEST['edit']['field_some_field_name'])) {
        foreach($_REQUEST['edit']['field_some_field_name'] as $empty_default_value) {
         $empty_default_values[] = array('nid'=>0);
        }
      }
return $empty_default_values;

Then, just to clarify, you still need to pass the stuff via REQUEST:
edit[field_some_field_name][0][nid][nid]=[nid:21]&edit[field_some_field_name][1][nid][nid]=[nid:20]

So, that works, but it is ugly that you have to do it for each field.

"The" solution, which I never got to do, seems to be to interject in the moment when drupal gets type information, but, type information is cached, and I could not find a way to "bypass" that cache. Also, I could not find any hook at any useful point in the execution. In any case, the architecture of prepopulate is not designed to do such thing: which is fine, since it gives the flexibility to tweak any field, not just content fields.

Hope this helps!

Anonymous’s picture

I have the same problem and I don't know how to solve it. Any help?

Anonymous’s picture

Version: 6.x-1.1 » 7.x-2.0
Category: Feature request » Bug report
Priority: Normal » Critical
nwom’s picture

Version: 7.x-2.0 » 7.x-2.x-dev
Category: Bug report » Feature request
Priority: Critical » Normal
Status: Active » Closed (duplicate)
nwom’s picture