Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

mailing list query returns null #363

Closed
1stevengrant opened this issue Feb 2, 2023 · 12 comments
Closed

mailing list query returns null #363

1stevengrant opened this issue Feb 2, 2023 · 12 comments
Labels
bug Something isn't working

Comments

@1stevengrant
Copy link

Kicking the tyres on Campaign for a project.

I've configured the plugin and in the control panel I can see mailing list, contacts but for some reason, when I query the mailing list based on id, as per the docs

{% set mailingList = craft.campaign.mailingLists.id(49861).one() %}

{% if mailingList %}
   <h1> Subscribe to {{ mailingList.title }}</h1>
{% endif %}

the mailing list definitely exists, I've tried deleting it and recreating but still the same issue. I can see the mailing list in the database also.

I'm stumped. Any gotchas that I'm missing?

I've also tried getting by handle and slug 🤷‍♂️

@1stevengrant 1stevengrant added the bug Something isn't working label Feb 2, 2023
@bencroker
Copy link
Collaborator

Have you double checked that the mailing list is enabled and that the mailing list type is enabled for the site you're testing with?

@1stevengrant
Copy link
Author

aha - that's what's thrown me...the relationship between a mailing list and site.

Here's my conundrum, we have multiple sites in this instance.

We have an organisation site and a site for a conference the organisation operates.

The mailing list was assigned to the organisation but being called on the conference site. Is there a way to do that?

@bencroker
Copy link
Collaborator

bencroker commented Feb 2, 2023

Have you tried adding .siteId(1) to the query, replacing 1 with the site ID the mailing list type is enabled for?

@1stevengrant
Copy link
Author

brill, thanks so much @bencroker - just the job

@1stevengrant
Copy link
Author

@bencroker another likely dumb question but with this snippet

<form method="post" action="">
                        {{ csrfInput() }}
                        <input type="hidden" name="action" value="campaign/forms/subscribe" />
                        <input type="hidden" name="mailingList" value="{{ mailingList.slug }}" />
                        <input type="hidden" name="redirect" value="{{ 'subscribe-success'|hash }}" />

when submitting the form I get the error Mailing list not found in /vendor/putyourlightson/craft-campaign/src/controllers/FormsController.php

is that because it's trying to find a form with that particular slug in the context of the current site?

@bencroker
Copy link
Collaborator

Yes, it looks like the same issue as above.

@1stevengrant
Copy link
Author

Yes, it looks like the same issue as above.

so that will never work the way I intend then doing

{% set mailingList = craft.campaign.mailingLists.siteId(4).id(49863).one() %}

<form method="post" action="">
                        {{ csrfInput() }}
                        <input type="hidden" name="action" value="campaign/forms/subscribe" />
                        <input type="hidden" name="mailingList" value="{{ mailingList.slug }}" />
                        <input type="hidden" name="redirect" value="{{ 'subscribe-success'|hash }}" />
...

@bencroker
Copy link
Collaborator

bencroker commented Feb 3, 2023

Yeah I see what you mean. I may add an optional siteId parameter to the forms controller. Are you running Campaign 2?

@1stevengrant
Copy link
Author

yeah, latest version. That would be useful. Appreciate this is probably quite edge case.

My workaround for now is to use a Freeform form to capture details and hook up their Campaign integration in the background.

@bencroker
Copy link
Collaborator

I added an optional siteId parameter to the front-end subscribe and unsubscribe forms in 5f068f2 and released in version 2.5.3.

<input type="hidden" name="siteId" value="2" />

@1stevengrant
Copy link
Author

what a man! thank you

@bencroker
Copy link
Collaborator

FYI I updated the docs at https://putyourlightson.com/plugins/campaign#front-end-forms

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants