Well I managed to figure most of this out using [Formit] - but I still have one question, I can grab the errors, custom errors for the hooks.... but how do I grab/set a success message????
Here is what I have:
this is the chunk tht holds the form etc:
[[!FormIt?
&hooks=`spam,mcSubscribeCallout`
&validate=`mailchimpsubscribe:required:email,nospam:blank`
&placeholderPrefix=`mc.`
]]
<div id="mailchimp" class="call-out">
<h3>Sign-up for Our E-Newsletter</h3>
<form action="[[~[[*id]]]]" method="post" class="form" name="mailchimp-subscribe">
<input type="hidden" name="nospam" value="" />
<ul>
<li class="newsletter-icon"></li>
<li class="newsletter-signup">
<label>Email Address<span style="color:red;">*</span></label>
<input type="text" name="mailchimpsubscribe" value="[[+!mc.mailchimpsubscribe]]" maxlength="50" class="text-input" />
</li>
<li class="newsletter-submit">
<input type="submit" name="mailchimpsubscribe-submit" value=" " class="submit-input" />
</li>
</ul>
</form>
[[!+mc.subsuccess]]
[[!+mc.error.mailchimpsubscribe:notempty=`<span class="mc-subscribe-error">[[!+mc.error.mailchimpsubscribe]]</span>`]]
[[!+mc.error_message:notempty=`<span class="mc-subscribe-error">[[!+mc.error_message]]</span>`]]
<!--[ [!+mc.error.mailchimp:notempty=`<span class="mc-subscribe-error">[[!+mc.error.mailchimp]]</span>`] ]-->
</div>
Here is the mcSubscribeCallout snippet:
<?php
include_once('assets/MCAPI/mcapi.class.php');
$email = $hook->getValue('mailchimpsubscribe');
$action = 'listSubscribe';
$api = new MCAPI($apikey);
$merge_vars = array('FNAME'=>'Anonymous', 'LNAME'=>'User');
$retval = $api->$action( $listId, $email, $merge_vars );
if ($api->errorCode){
//$mcerror = '[Error:' . $api->errorCode . '] ';
$mcerror .= $api->errorMessage;
$hook->addError('mailchimp',$mcerror);
return false;
} else {
return true;
}
So this works perfectly, it returns errors and submits addresses for subscriptions returning ’true’ - which is fine... but I need to display a success message I would like to add something to the mcSubscribeCallout snippet like:
} else {
$hook->addMessage('subsuccess','Subscription successful!');
return true;
}
Then in the form chunk:
[!+mc.message:notempty=`<span class="mc-subscribe-success">[[!+mc.message.subsuccess]]</span>`]]
However, that is just a guess at the syntax of the $hook .... I get an error the addMessage is not a valid method [naturally! it was just a guess] - are the methods for this documented somewhere?
Any thoughts?
-thanks
-sean