Forum
Mailchimp App - interests/groups - how to link to checkboxes
Hello,
I'm trying to subscribe a user to Mailchimp list and let them choose which groups/interests they want to be added to.
The Perch docs for this suggest using a hidden field:
<perch:input type="hidden" id="cheese" value="a375f7a461" mailer="interests" />
but I'm assuming that's almost an "auto-submit" method, where you'd hard-code the interests you want the user to be added to.
I've tried to change the above to a checkbox:
<perch:input type="checkbox" id="cheese" value="a375f7a461" mailer="interests" />
but this is causing an invalid response from the Mailchimp API:
[body] => {"type":"https://developer.mailchimp.com/documentation/mailchimp/guides/error-glossary/","title":"Invalid Resource","status":400,"detail":"Invalid interest ID: '_empty_'.","instance":""}
so my ID isn't getting through.
Would I need to wrap the original interest hidden field in a Perch if
and then only output it if a checkbox is checked?
If that's the case, I'm not sure of what syntax to use because Perch checkboxes and ifs look to be somewhat different if they're inside a Perch form. I've tried this, with the same _empty_
result:
<perch:input type="checkbox" value="1" id="choose_cheese" />
<perch:if id="choose_cheese" value="1">
<perch:input type="hidden" value="a375f7a461" mailer="interests" id="cheese" />
</perch:if>
Thanks for any suggestions,
Gareth
Of course - all a Perch checkbox can do at this point is stop the hidden interest fields from outputting to the page in the first place, when it first renders to the page. I'll have to intercept the values the user wants on form submission somehow.
Is this resolved?
Hello - I've written a Perch app to pick up the form submission. That's reading which checkboxes the user ticked, and based on that is sending hard-coded interest IDs through to a new PHP Class that extends your
PerchMailChimp_Subscribers
class, with a modified version of thesubscribe_from_form
function.Ta.
Ok, great.