SmartForms and Mailchimp API
-
- Forum Members
- Posts: 200
- Joined: Mon Nov 26, 2018 3:09 pm
SmartForms and Mailchimp API
Has anyone used these together ... and can give me any pointers?
Is there a way of processing parts of a SmartForm from so that the Mailchimp API is called and values are sent? Not sure if its possible in SmartForms ... would need to be some kind of handler in SmartForm where I can process PHP I assume, but I can't see a way of doing that...
Any guidance appreciated !
Is there a way of processing parts of a SmartForm from so that the Mailchimp API is called and values are sent? Not sure if its possible in SmartForms ... would need to be some kind of handler in SmartForm where I can process PHP I assume, but I can't see a way of doing that...
Any guidance appreciated !
Re: SmartForms and Mailchimp API
IIRC you can use a handler with smarty, hence calling a UDT (or plugin) and passing parameters
Re: SmartForms and Mailchimp API
Yes, you can process parts of a SmartForm in CMS Made Simple to call the Mailchimp API by using a UDT as a form handler:
1) Create a UDT:
Go to Extensions > User Defined Tags and create a new UDT. Name it send_to_mailchimp. Add the following PHP code to handle the Mailchimp API call:
2) Modify the SmartForm to Call the UDT:
Add a hidden field to your SmartForm to specify the UDT handler. Update your form code like this:
3) Process the Form:
I personally like to use ajax but let me know how it goes
1) Create a UDT:
Go to Extensions > User Defined Tags and create a new UDT. Name it send_to_mailchimp. Add the following PHP code to handle the Mailchimp API call:
Code: Select all
$api_key = 'your_mailchimp_api_key';
$list_id = 'your_list_id';
$email = $_POST['email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$data_center = substr($api_key,strpos($api_key,'-')+1);
$url = 'https://' . $data_center . '.api.mailchimp.com/3.0/lists/' . $list_id . '/members/';
.........
Add a hidden field to your SmartForm to specify the UDT handler. Update your form code like this:
Code: Select all
<input type="hidden" name="m1_udt" value="send_to_mailchimp">
Code: Select all
{if isset($_POST.m1_udt) && $_POST.m1_udt == 'send_to_mailchimp'}
{send_to_mailchimp}
{/if}
-
- Forum Members
- Posts: 200
- Joined: Mon Nov 26, 2018 3:09 pm
Re: SmartForms and Mailchimp API
oooh... thanks for this! Let me try it out!
Re: SmartForms and Mailchimp API
it's possible that "m1_" will need to be "cntnt01" check {$actionid}
Re: SmartForms and Mailchimp API
I don't understand why to use the hidden field. Could you explain it?
Re: SmartForms and Mailchimp API
I guess it's not necessary if you want to trigger the UDT on every submission.
-
- Forum Members
- Posts: 200
- Joined: Mon Nov 26, 2018 3:09 pm
Re: SmartForms and Mailchimp API
What do I need to do if not using the hidden field? I would like to trigger the UDT on every submission ... thanks!
-
- Forum Members
- Posts: 200
- Joined: Mon Nov 26, 2018 3:09 pm
Re: SmartForms and Mailchimp API
Bit stuck on this (no surprise!) ... does all this code:
go directly in the SmartForm design template ... for example just above where the code for the submit button is?
I tried the above but nothing seems to be happening
...grateful for any help!
Code: Select all
<input type="hidden" name="m1_udt" value="send_to_mailchimp">
{if isset($_POST.m1_udt) && $_POST.m1_udt == 'send_to_mailchimp'}
{send_to_mailchimp}
{/if}
I tried the above but nothing seems to be happening
...grateful for any help!
Re: SmartForms and Mailchimp API
two options you could try:
1) inside your form template:
{smtfm_form_errors assign='errors'}
{if !empty($errors)}
<ul class="error">
{foreach $errors as $err}
<li>{$err}</li>
{/foreach}
</ul>
{/if}
{send_to_mailchimp}
<form>
2) try putting the {send_to_mailchimp} in the "Form Output" tab in the "Smarty template for the final message to display to the user" box when you edit a form
1) inside your form template:
{smtfm_form_errors assign='errors'}
{if !empty($errors)}
<ul class="error">
{foreach $errors as $err}
<li>{$err}</li>
{/foreach}
</ul>
{/if}
{send_to_mailchimp}
<form>
2) try putting the {send_to_mailchimp} in the "Form Output" tab in the "Smarty template for the final message to display to the user" box when you edit a form
Re: SmartForms and Mailchimp API
I think you should have a good understanding of the module to use it.
Have a look at the help, the Validation tab and the available Handlers.
Note that there's a 'POST form results to a URL/WebHook' handler, a 'Stop processing dispositions based on a condition' (it allows Smarty) and a 'Validate via Smarty' validation option.
I expect you can choose one to do what you want.
Have a look at the help, the Validation tab and the available Handlers.
Note that there's a 'POST form results to a URL/WebHook' handler, a 'Stop processing dispositions based on a condition' (it allows Smarty) and a 'Validate via Smarty' validation option.
I expect you can choose one to do what you want.
Re: SmartForms and Mailchimp API
"Stop processing dispositions based on a condition" seems to be also an option. It will not give you the thank you message
Re: SmartForms and Mailchimp API
Well, if you make sure your Smarty code doesn't output anything on success, other dispositions will continue.
PLUS, as stated in the description, the final 'disposition' will be done anyway. I think that makes it possible to show the 'thank you message' regardless of the outcome of the earlier dispositions.
PLUS, as stated in the description, the final 'disposition' will be done anyway. I think that makes it possible to show the 'thank you message' regardless of the outcome of the earlier dispositions.
Last edited by velden on Tue May 21, 2024 9:31 am, edited 1 time in total.
Reason: typo
Reason: typo
Re: SmartForms and Mailchimp API
i think the important thing is, we gave our new friend johnboyuk1 some material to work with.
-
- Forum Members
- Posts: 200
- Joined: Mon Nov 26, 2018 3:09 pm
Re: SmartForms and Mailchimp API
Yes - super helpful. I'm getting somewhere now I've got the full API code...I have something rudimentary working, I'll paste full Mailchimp API code when im done in case it's useful to anyone else.