I am having the same problem seen here which was an issue with version 5x-1.0-beta1.

Here's the problem in detail:
If I have an existing Page node with a node-reference type of Story:

  • While EDITING the existing Page node...
  • On the Page edit form, I click the "Add Story" link
  • Popup appears with node add form for Story
  • I fill out form and click "Submit"
  • Pop-up disappears and I see the "loading" animation for a few seconds.
  • New pop-up appears with success message "Your Story has been created", but below the message is a blank Submit Page form - which I was in the middle of filling out on the source form.
  • I close the popup, the drop-down list on the source form does not contain the newly added node as an option.

The module works amazingly on NEW Pages but not when editing EXISTING pages. From the looks of the other thread i referenced above, the problem exists in the "Add Page" link.

in my case the link is:
http://localhost/node/add/story?destination=node/add/page>

when I believe it should be:
http://localhost/node/add/story?destination=node/TheNodeNumber/edit>

Is there some function in the code to determine the source page's address before writing out the "Add Page" link?

Comments

nodecode’s picture

Correction: in the above issue, wherever i said "Add Page" i meant "Add Story"

nodecode’s picture

I can confirm that the module does in fact work properly when editing existing content if i use Firebug to change the "Add Story" link to something like
http://localhost/node/add/story?destination=node/22/edit
(assuming node/22/edit was the page from which i called the popup form).

Upon examination of the module's code, it appears that line #87 is the creating the problem.
$links[] = l("Add ". $all_types[$type]->name, $path, array('class' => $pclass), "destination=node/add/" . strtr($src_type, '_', '-'));

As you can see destination=node/add/ is hardcoded here. My thoughts are that the entire last part of line #87 should be replaced by the current url. The logic seems simple but i'm a novice at coding with php/drupal so I can't really say for sure.

Does this make sense to anyone else? I mean shouldn't clicking on the "Add xxx" link create a popup which, after you 'Submit' it, ALWAYS sends you back to the URL from which it was called? I'm going to start cutting my teeth on this bit of code. If anyone has any ideas or can suggest some functions i can use to get the source form's url and strip the base url from it, please let me know.

nodecode’s picture

Okay so i spent 10 minutes fixing the problem and 2 hours trying unsuccessfully to create a patch. grrrrr!

Here's the code: It starts at line #84. I added 1 line after line #86 and edited line #88 (which was previously line #87).

foreach ($field['referenceable_types'] as $type => $value) {
    if (!empty($value) && user_access("create $type content")) {
      $path = "node/add/". strtr($type, '_', '-');
+     $url = $_GET['q'];
+     $links[] = l("Add ". $all_types[$type]->name, $path, array('class' => $pclass), "destination=$url");
-     $links[] = l("Add ". $all_types[$type]->name, $path, array('class' => $pclass), "destination=node/add/" . strtr($src_type, '_', '-'));
    }

So far it works great for creating a bug-free "Add xxxx" link both when ADDING and EDITING parent nodes. Someone should turn this into a patch if it helps them too...

hefox’s picture

http://api.drupal.org/api/function/drupal_get_destination/5

Probably should just use drupal_get_destination() since that's what it's intended for I thinks:P.

ie

+     $links[] = l("Add ". $all_types[$type]->name, $path, array('class' => $pclass), drupal_get_destination());
matt2000’s picture

Status: Needs review » Reviewed & tested by the community

Confirming that this is still an issue and #4 is an effective solution. Do we need a patch to get this one-line change in?

nodecode’s picture

I switched to D6 and havent installed this yet on the new system. I know my code in #3 worked when I used it on my D5 site. I'm very curious to know if this is a problem with the 6.x-1.0 version because i want to install it soon. If anyone knows I'd like to know too.

nodecode’s picture

Bump. does anyone know if this is an issue with the 6.x version also?