by
potato » Mon Jul 07, 2014 2:15 pm
I have finally used Cheesypoof's code for a MailChimp signup form ( - after battling with the MailChimp embed form previously with trying to override styles and getting inline validation to work - it kept going off to the MailChimp hosted error page!). Thank you cheesypoof - superbly well documented ...
I used the stripped down code ...
- Code: Select all
<cms:form action="<cms:link 'newsletter.php'/>" method='post' name='subscribe'>
<cms:input name='email' placeholder='Email Address' required='1' type='text' validator='email'/>
<input type="submit" value="Subscribe to Newsletter">
</cms:form>
in another template mailinglist.php - but found that when there is a validation error (say, invalid email address) the user is taken from current page off to newsletter.php for the error to display. I'm guessing that this is how it works - or have I implemented the solution wrongly?
I changed it to the following in mailinglist.php:
- Code: Select all
<?php require_once( 'admin/cms.php' ); ?>
<?php require_once( 'MailChimp.php' ); ?>
<cms:template title='Mailing List'>
......
<div id="form2">
<cms:form method='post' name='subscribe'>
<cms:if k_success>
<cms:check_spam email=frm_email />
<cms:php>
$MailChimp = new \Drewm\MailChimp(' ... MAILCHIMP API KEY HARDCODED HERE ...');
$result = $MailChimp->call('lists/subscribe', array(
'id' => ' ... MAILCHIMP LIST ID HARDCODED HERE ...',
'email' => array('email' => '<cms:show frm_email/>')
));
if (isset($result['email'])) {
echo "<div class=\"success\">We have sent you an email - please click on the link to confirm your subscription!</div>";
} else if (isset($result['status']) &&
$result['status'] === 'error' &&
$result['name'] !== 'List_AlreadySubscribed') {
echo "<div class=\"error\"><strong>" . $result['name'] . " (" . $result['code'] . "):</strong> " . $result['error'] . "</div>";
} else {
echo "<div class=\"error\">An unknown error was encountered. Please try again later or contact us.</div>";
}
</cms:php>
<cms:else/>
<fieldset>
<legend>Sign up to our newsletter</legend>
<div class="form-group<cms:if k_error_email> has-feedback</cms:if>">
<label class="sr-only control-label" for="email">Email</label>
<cms:input type="text"
class="form-control"
name="email"
placeholder='your email address'
maxlength="100"
required='1'
validator='email'
validator_msg='required=Please enter your email address! | email=Sorry - not a valid email address'
/>
<cms:if k_error_email><span class="glyphicon glyphicon-remove form-control-feedback position-icon"></span><span class="k-error"><cms:show k_error_email /></span></cms:if>
</div>
</fieldset>
<button type="submit" class="btn btn-default">Sign up!</button>
</cms:if>
</cms:form>
</div>
As I am doing this somewhat blindly - copying and amending from an expert - I just wondered if there was anything I am missing?!