2
0

mailchimp.rst 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. Mailchimp Integration
  2. =====================
  3. Implementations of the abstract `CoderedFormPage` can add their form submissions to a Mailchimp list.
  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. Implementation
  7. ~~~~~~~~~~~~~~
  8. By default, when you generate a website, you will get an implementation of `CoderedFormPage`.
  9. To get the functionality working, you need to do the following:
  10. - Implmenet the abstract `MailchimpSubscriberIntegration` class with a `ParentalKey` that points to your `FormPage`
  11. - Add an `integrations_panels` variable to `FormPage` that holds an `InlinePanel` for your implemented `MailchimpSubscriberIntegration` class
  12. Here is what the resulting code will look like in ``website/models.py``::
  13. from modelcluster.fields import ParentalKey
  14. from coderedcms.models import CoderedFormPage, MailchimpSubscriberIntegration
  15. from wagtail.admin.edit_handlers import InlinePanel
  16. class FormPageMailchimpSubscriberIntegration(MailchimpSubscriberIntegration):
  17. page = ParentalKey('FormPage', related_name='mailchimp_subscriber_integrations', on_delete=models.CASCADE)
  18. class FormPage(CoderedFormPage):
  19. """
  20. A page with an html <form>.
  21. """
  22. class Meta:
  23. verbose_name = 'Form'
  24. template = 'coderedcms/pages/form_page.html'
  25. integration_panels = [
  26. InlinePanel('mailchimp_subscriber_integrations',
  27. heading="Mailchimp Subscriber Integrations",
  28. )
  29. ]
  30. Next run ``python manage.py makemigrations website`` and ``python manage.py migrate`` to
  31. make the changes to your project. You will also need to add your api key to the Mailchimp API settings in the CMS.
  32. How to Use
  33. ~~~~~~~~~~
  34. When you make or edit a `FormPage`, you will now see an "Integrations" tab. Clicking the plus icon will instantiate an integration.
  35. You can add as many of these integraitons objects as you need. This is useful if you want to send a submission to more than one list.
  36. When you select a list, the instance will load in the merge variables and interest categories. The interest categories are straightforward.
  37. You just select the interests you want the submission to have.
  38. The merge variables are a bit more complex. They work similarly to the emails that are sent after a form submission.
  39. 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
  40. 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",
  41. "First Name", "Phone", the context variables will be `email_address`, `first_name`, `phone`. So if you have a merge variable, FIRSTNAME, you would want
  42. to input `{{ first_name }}` into that field.
  43. 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.