We have a view which is returning a list of people to which we have attached two Mailing Label displays. Each uses php code to pull an address from the person record, one getting an in-state address and another an out-of-state address. By themselves, each display works correctly. When both are attached, though, submitting either Mailing Label form returns the results of the first form.

Somewhere the wires are getting crossed but I can't seem to make sense of where/how it's happening. Any suggestions?

If I can get it working, I'm happy to turn it into a patch.

Comments

acouch’s picture

What an annoying bug. Thanks for reporting it.

It looks like the culprit is where it grabs the display on line 29 of mailing_label_plugin_display_attachment.inc:

$current_display = $this->view->current_display;

If I'm right, I'm not sure why it doesn't grab the current display each time. I honestly won't have much time to troubleshoot this in the near future, so please give it a shot if you can.

darrellduane’s picture

+1

barrett’s picture

[edit: adding notes about when each output set is created]

Thanks for getting back to me, Aaron. It looks like the bug is actually downstream from that point you referenced though. Doing some output printing (see below) the correct results are getting into the form but what is getting passed to the submit function when I submit the mailing_2 form is the results from the mailing_1 form.

I don't have the answer yet, but at least I'm in the neighborhood....I think.

Output information. For both these records, the phpcode values in mailing_2 should be empty as they do not have an out-of-state address.
Output at form build, before submission

    * current display: mailing_1
    * results at bottom of mailing_label_plugin_display_attachment::render Array ( [0] => Array ( [phpcode] => Person 1 in-state address ) [1] => Array ( [phpcode] => Person 2 in-state address ) )
    * $results at top of mailing_label_form: Array ( [0] => Array ( [phpcode] => Person 1 in-state address ) [1] => Array ( [phpcode] => Person 2 in-state address ) )
    
    * current display: mailing_2
    * results at bottom of mailing_label_plugin_display_attachment::render Array ( [0] => Array ( [phpcode] => ) [1] => Array ( [phpcode] => ) )
    * $results at top of mailing_label_form: Array ( [0] => Array ( [phpcode] => ) [1] => Array ( [phpcode] => ) )

Output when form is submitted

$results in mailing_label_form_submit: Array ( [0] => Array ( [phpcode] => Person 1 in-state address ) [1] => Array ( [phpcode] => Person 2 in-state address ) )
acouch’s picture

Thanks for debugging this far. I still think it is where the results are generated in mailing_label_plugin_display_attachment.inc starting at line 31 where it is grabbing the view. You may be able to see the view but that doesn't mean the $results are passed to the form. I'll take a look this week.

barrett’s picture

I haven't been able to test the theory yet, but I found two articles (below) that discuss this same problem with other forms when two copies of the same form are rendered on a page. Seems like Drupal gacks when two forms have the same form_id. If that's right, it's not a problem with the module but something probably best solved up-stream in the attachment plugin routines.

http://drupal.org/node/267304
http://www.computerminds.co.uk/drupal-6-multiple-instances-same-form-one...

letapjar’s picture

Status: Active » Needs review
StatusFileSize
new2.71 KB

Barrett, you are right about the cause - but we can fix this in the module.

Basically we need to grab the name of each separate mailing label attachment within the plugin display attachment and pass it to the function that calls drupal_get_form. then we need to implement hook_forms() to map all the different form instances to the same form builder and submit functions.

try out the attached patch.

NOTE: this patch assumes that you have named each instance of the mailing label attachment uniquely - if not the form will still gaack. I tried this with mailing labels where the first name and last name were transposed in 2 separate attachments and viola - i got two distinct files.

One thing I'm unsure about - I had to use a global $forms variable in the module. not sure if that is a drupal no-no. But it was the only way to keep hook_forms from overwriting the same array every time it was called from the various instances of the mailing label form.

barrett’s picture

Thanks, letapjar. I've moved on from the project which lead me to discover the issue, but I've forwarded your response on to the current developers to look into.

letapjar’s picture

StatusFileSize
new1.66 KB

re-worked this patch through git to have no prefixes

letapjar’s picture

StatusFileSize
new465 bytes

The patch in #8 above is incomplete - the plugin display attachment needs to return the current_display on line 87 to make this work properly - patch attached - note this patch should be applied in addition to the patch in #8 to get a complete solution.

bluegeek9’s picture

Issue summary: View changes
Status: Needs review » Closed (outdated)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.