statamic-rad-pack / mailchimp

Mailchimp integration for Statamic
https://statamic.com/addons/rad-pack/mailchimp
MIT License
19 stars 13 forks source link

Checkbox on consent boolean/array #49

Closed dave-smyth closed 3 years ago

dave-smyth commented 3 years ago

Not sure if this is an add-on issue, apologies if not...

I’m using a checkbox field as a consent and submitting the form with this checked returns:

Return value of Silentz\Mailchimp\Subscriber::hasConsent() must be of the type bool, array returned

The relevant part of the blueprint:

-
        handle: mailing_list
        field:
          inline: false
          options:
            'true': 'Subscribe me to the mailing list'
          display: 'Mailing List'
          type: checkboxes
          icon: checkboxes
          listable: hidden

Can anything be done to recognise this field/array? I’d guess a radio would work, but would prefer for users to be able to check/uncheck.

Perhaps I need to set this up a different way?

edalzell commented 3 years ago

Nice find.

edalzell commented 3 years ago

@websmyth what does your template code look like for that mailing_list field?

My template code looks like this and it works fine:

        <div class="form-group">
            <label>Permission</label>
            <input type="checkbox" name="permission" value="true" class="form-control"/>
        </div>
dave-smyth commented 3 years ago

I’m looping over the fields:

<div class="formFields">
  {{ fields }}
    <div class="field {{ type }}Field">
      {{ if type !== "checkboxes" }}
         <label for="{{ handle }}" class="fieldLabel">{{ display }}</label>
      {{ endif }}
        <div>{{ field }}</div>
    </div>
  {{ /fields }}
</div>

That produces:

<div class="field checkboxesField">
  <div>
     <label><input type="checkbox" name="mailing_list[]" value="true" >Subscribe me to the mailing list</label>
  </div>
</div>
edalzell commented 3 years ago

ok that's what I thought, easy fix.