2
0

mailchimp.rst 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. Mailchimp Integration
  2. =====================
  3. This feature can automatically subscribe someone to a Mailchimp email list when they submit a form.
  4. When this functionality is enabled, you can map form submission variables to merge variables and add
  5. form submissions to specific interest groups.
  6. For example, if you have a contact form, you might want to opt-in submitters to a newsletter Mailchimp list.
  7. And if you have a sales inquiry form, you could opt-in those submitters to a separate sales Mailchimp list
  8. with a particular interest group.
  9. Implementation
  10. --------------
  11. By default, when you generate a website, you will get an implementation of ``CoderedFormPage``.
  12. To get the functionality working, you need to do the following:
  13. - Implement the abstract ``MailchimpSubscriberIntegration`` class with a ``ParentalKey`` that points to your ``FormPage``
  14. - Add an ``integrations_panels`` variable to ``FormPage`` that holds an ``InlinePanel`` for your implemented ``MailchimpSubscriberIntegration`` class
  15. Here is what the resulting code will look like in ``website/models.py``::
  16. from modelcluster.fields import ParentalKey
  17. from coderedcms.models import CoderedFormPage, MailchimpSubscriberIntegration
  18. from wagtail.admin.edit_handlers import InlinePanel
  19. class FormPageMailchimpSubscriberIntegration(MailchimpSubscriberIntegration):
  20. page = ParentalKey('FormPage', related_name='mailchimp_integrations', on_delete=models.CASCADE)
  21. class FormPage(CoderedFormPage):
  22. """
  23. A page with an html <form>.
  24. """
  25. class Meta:
  26. verbose_name = 'Form'
  27. template = 'coderedcms/pages/form_page.html'
  28. integration_panels = [
  29. InlinePanel('mailchimp_integrations',
  30. heading="Mailchimp",
  31. )
  32. ]
  33. Next run ``python manage.py makemigrations website`` and ``python manage.py migrate`` to
  34. make the changes to your project. You will also need to add your API key to the Mailchimp API settings in the CMS.
  35. How to Use
  36. ----------
  37. When you make or edit a ``FormPage``, you will now see an "Integrations" tab. Clicking the plus icon will instantiate an integration.
  38. You can add as many of these integration objects as you need. This is useful if you want to send a submission to more than one list.
  39. When you select a list, the instance will load in the merge variables and interest categories. The interest categories are straightforward.
  40. You just select the interests you want the submission to have.
  41. The merge variables are a bit more complex. They work similarly to the emails that are sent after a form submission.
  42. You can decide what values from your form are put into which merge variables. These values will get rendered by the Django renderer, as such
  43. they use the same syntax. The context for the render will be your form submission fields. For example, if you have fields named "Email Address",
  44. "First Name", "Phone", the context variables will be ``email_address``, ``first_name``, ``phone``. So if you have a merge variable, FIRSTNAME, you would want
  45. to input ``{{ first_name }}`` into that field.
  46. That's it. Whenever a user fills out the form on the front end, they will be subscribed to your Mailchimp list with the merge fields and interest categories that you configure.