revolunet / react-mailchimp-subscribe

React subscribe form for Mailchimp.
https://revolunet.github.io/react-mailchimp-subscribe/
245 stars 48 forks source link

Adding GDPR fields and a few examples #12

Open khollund opened 6 years ago

khollund commented 6 years ago

Hi. This was a very handy thing to plug in, I would have loved to see examples of adding more advanced fields though, maybe an expanded example. For instance I wanted to adopt GDPR early but couldn't quite figure out how to get the data sent. I ended up hacking in this:

onValidated({ EMAIL: email.value, FNAME: fname.value, LNAME: lname.value, GDPR: {[27]: gdpr.value} });

It triggers a warning though, any ideas how to do it in a better way? The bracket in the variable name was my main issue, they expect gdpr[27] for the GDPR email field.

khollund commented 6 years ago

I actually found out it doesn't consistently add the GDPR value so I ended up making my own instead. I can make a PR for the richer implementation of the form as an example when I get it done.

idmontie commented 5 years ago

It looks like the GDPR values are different per account. Mine was gdrp[37317].

Here is how I implemented it:

<MailchimpSubscribe
  url={URL}
  render={({ subscribe, status, message }) => (
    <form onSubmit={e => {
      e.preventDefault();
      const form = e.target;

      const formData = {
        EMAIL: form.email.value,
        [GDPR_NAME]: form.gdpr.checked ? form.gdpr.value : '',
      };

      subscribe(formData);
  }}>
    {/* ... */}
  </form>
</MailchimpSubscribe>