Hi, I've spent hours trying to prepopulate the autocompleting content taxonomy field from this code snippet:

<fieldset class="group-date"><legend>Date</legend><div class="form-item" id="edit-field-reference-date-value-wrapper">
 <label for="edit-field-reference-date-value">Date: </label>
 <input type="text" maxlength="255" name="field_reference_date[value]" id="edit-field-reference-date-value" size="60" value="" class="form-text form-autocomplete" />
 <div class="description">YYYYMMDD</div>
</div>
<input class="autocomplete" type="hidden" id="edit-field-reference-date-value-autocomplete" value="http://vacilando.net/content_taxonomy/autocomplete/field_reference_date" disabled="disabled" /></fieldset>

In the prepopulate URL I tried edit[field_reference_date][value], edit[field_reference_date][value][autocomplete], edit[field_reference_date][0], even edit[form_item][field_reference_date][value] (to include the wrapper class ID like it's done with the body tag), etc., etc. and I've read the documentation and tons of forum contributions, but nothing seems to work.

I would appreciate very much your suggestions for the above code, or clear description (or reference to one) of what Prepopulate needs to locate the correct input tag. Thanks!

Comments

vacilando’s picture

Following http://drupal.org/node/307669#comment-1043488 I also tried edit[group_date][field_reference_date][value] (where group_group date comes from the fieldset class) -- but without success.

916Designs’s picture

Title: Prepopulating from CCK » Prepopulating CCK Autocomplete Nodereference field
Version: » 6.x-1.1

So I messed around with things and got lucky. My autocomplete nodereference is set for one content type only, haven't tried multiple.

html of form:

<input type="text" class="form-text form-autocomplete required text" value="" size="60" id="edit-field-mo-faculty-id-0-nid-nid" name="field_mo_faculty_id[0][nid][nid]" autocomplete="OFF"/>

I ended up successfully populating field with this link:

/node/add/member-of?edit[field_mo_faculty_id][0][nid]=97

I created it in the content template for the type of my reference, and thus passed the nid:

$path = $base_url . '/node/add/member-of?edit[field_mo_faculty_id][0][nid]='.$node->nid;

So anyway... strange. You would expect to populate field_mo_faculty_id[0][nid][nid] but I only populated field_mo_faculty_id[0][nid], and not with the title of the content, but with its nid.

leoklein’s picture

I ended up successfully populating field with this link:

/node/add/member-of?edit[field_mo_faculty_id][0][nid]=97

Just what I needed. Thanks!

Chris Einkauf’s picture

A quick note to future readers of this issue: I found that this method only works if your autocomplete node reference field is set to "Autocomplete matching: Starts with" (as opposed to "Autocomplete matching: Contains").

egsj’s picture

I had Prepopulate successfully filling out a user reference and a node reference field for me but it recently stopped working and I am unsure why. There have been no changes to the field names.

Here is what I have:

name="field_whichjob[0][nid][nid]"
id="edit-field-whichjob-0-nid-nid"

name="field_submitto[0][uid][uid]"
id="edit-field-submitto-0-uid-uid"

and in the URL ?edit[field_whichjob][0][nid]=594&edit[field_submitto][0][uid]=54

I have verified it is not a permissions or view problem as these fields will look up the values if manually entered.

Any help is much appreciated.

egsj’s picture

They are in fieldgroups but the previously listed thread did not help, and they were always in fieldgroups.

egsj’s picture

Any ideas?

egsj’s picture

However,

?edit[field_whichjob][0][nid]=742 did not work.

field is set to "starts with..."

does also find the node when manually typed in.

aren cambre’s picture

Component: Documentation » Code
Category: support » bug

Too many problems above for this not to be a bug.

I can't get edit[field_fieldname][0][nid]=nid to work regardless of autocomplete matching or content type restrictions.

mdroste’s picture

"?edit[field_fieldname][0][nid] = nid" works for me in 6.x-1.1
Nothing works for me in 6.x.2. Not even normal textfields.

clemens.tolboom’s picture

Please install devel.module to check field structure instead of dumping html :)

Using http://example.com/node/add/test_node?edit[field_selectbox][0][nid]=5&ed... where there is a _select_ and a _autocomplete_ field.

Both are prepopulated fine on 6.x-1.1

So is this bug about 6.x-1.1 or 6.x-2.x-dev?

aren cambre’s picture

It's for 1.1.

I inspected field formats directly through the database to arrive at what I tried in #9. Are you using autocomplete on a node reference?

frankcarey’s picture

it's not working for me either. one thing to try is edit[field_nodereference][0][nid][nid]. (notice the double [nid])

egsj’s picture

Fixed by this much better module http://drupal.org/project/nodereference_url

frankcarey’s picture

correction ?edit[field_blog_entry][0][nid]=89 works fine for me (it is an autocomplete set to "contains"). my problem was that i forgot to click submit in my modules list, so the module was never enabled :P So it works for me now.

frankcarey’s picture

@ethangj ah, nodereference_url can be a useful module, but it didn't do 2 important things that I needed.

1) It won't let a user edit the node reference after the node is saved (they can't change it later).

2) It doesn't work with multiple entry fields.

clemens.tolboom’s picture

Maybe "contains" is key ... my node_reference autocomplete has a "contains".

garryi’s picture

I'm trying to accomplish the same thing, except I want to pass an argument into the field.
Can anyone give me step by step on accomplishing this?

damienmckenna’s picture

I've gotten it working with both v6.x-1.x and v6.x-2.x:

  • If your nodereference field is named "field_something" the string you should be using in the URL should be: edit[field_something][$count][nid]
  • The $count value is the field number to assign, starting at 0.
  • The node value to pass into a nodereference field is the nid of the node in question.
  • An example would be: edit[field_program][0][nid]=42
jmiccolis’s picture

Version: 6.x-1.1 » 6.x-2.0

This appears to be broken in the 2.0 release. I'm looking into the code now and should be able post back shortly with more details, and hopefully, a patch

jmiccolis’s picture

Version: 6.x-2.0 »
Status: Active » Needs review
StatusFileSize
new2.3 KB

The attached patch seems to fix the issue for me and also moves the all the recursion into the recursive function, instead of having the first iteration out side of it.

One note to noderef users... you'll need to do more than just pass the nid with 2.0 - you need to do at least something like `[nid: 52]`

damienmckenna’s picture

This doesn't work either. By the time prepopulate_after_build() runs the data structure has changed completely. I'll work on this later, a site I'm finishing has been using v1.x successfully until now.

Grayside’s picture

Priority: Normal » Major
Status: Needs review » Reviewed & tested by the community

Patch looks good, makes nodereference smooth like butter.

It's important to keep in mind the differences in how this operates:
edit[field_nodereference][0][nid][nid]=[nid: #]

If you try to use a title fragment, remember the autocomplete widget will not look up the node unless it gains focus on the page.

And of course, for development purposes you now need to extract the nid from the string.

jbrauer’s picture

Status: Reviewed & tested by the community » Needs review

This seems to work well. I'd like to get a few more reviews and will link this from another issue it fixes.

Re #22 please do not use the insecure version 1.x code on any sites as it leaves them exposed to security issues.

webkenny’s picture

mikey_p’s picture

Status: Needs review » Needs work
    _prepopulate_request_walk(&$form, &$request);

Call-time pass by reference is deprecated.

jbrauer’s picture

Status: Needs work » Needs review
StatusFileSize
new2.3 KB

Updated patch.

pkej’s picture

Status: Fixed » Needs work

The patch in #27 works well with nodereferences and body textarea, as well as fieldsets and cck fields inside those.

pkej’s picture

Status: Needs review » Reviewed & tested by the community

I posted into the thread before refreshing it. I was working with this issue and testing out prepopulate.

jbrauer’s picture

Status: Reviewed & tested by the community » Fixed

Committed to HEAD. New -dev release should be available within 12 hours. If we find no other big bugs a new release will be out this week.

Status: Needs work » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

dogboy72’s picture

StatusFileSize
new12.75 KB

I've got this working fine, but I have a user interface issue. The node reference fills with only the nid (i.e. [nid: 123]) instead of how it works normally. See attached.

I've tried both "starts with" and "contains" for the autocomplete settings. This is perhaps a feature request or a bug. Not sure.

Grayside’s picture

I suspect that is part of the problem with using #after_build. The nid is being put into place after the form looks up the title and inserts it.

thommyboy’s picture

so is this a bug? i used prepopulate before to prepopulate a (multivalued) nodereference and it stopped working some time ago.
changing the url helped to fill in the NID but the field only shows "123" instead of "title [123]" and the node does not save.
unfortunately nodereference_by_url does not work for me as it doesn't seem to support multi-valued fields...

Grayside’s picture

It's sort of a bug, and sort of a feature request because Prepopulate 2.0 rearchitected its functionality. You need to change the way you craft Prepopulate URLs for node references. See #23.