We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 26503
    • 620 Posts
    Hi;

    I have a mailchimp API all setup and running quite nicely for the user registration page ... now I have to set it up so that anonymous users can sign up from a sidebar callout box.
    - I need the users to stay on the current page (form will post to [[~[[*id]]]] )
    - I need to display the mcapi return value [success/error message] in the same callout.

    Wondering how to approach this, I have a couple problems:
    1. calling the mailchimp signup snippet [[!mailChimp? &subscribeemail=`*form variable*`]]
    - how can I call the snippet without it executing every time the page loads, I was considering using [[If]]
    2. How do I grab the ’subscribeemail’ form variable when form gets submitted?

    Remebering that the goal is to keep the user on the same page.

    -thanks
    -sean
      *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

      Sean Kimball CLP, CLS.
      Technical Director / Sr. Developer | BigBlock Studios
      ._______________________________________________.
      Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
      27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
      phone/fax: 905-426-5525
      • 26503
      • 620 Posts
      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





        *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

        Sean Kimball CLP, CLS.
        Technical Director / Sr. Developer | BigBlock Studios
        ._______________________________________________.
        Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
        27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
        phone/fax: 905-426-5525
        • 3749
        • 24,544 Posts
        Have you tried &successMessage and &successMessagePlaceholder?
          Did I help you? Buy me a beer
          Get my Book: MODX:The Official Guide
          MODX info for everyone: http://bobsguides.com/modx.html
          My MODX Extras
          Bob's Guides is now hosted at A2 MODX Hosting
          • 26503
          • 620 Posts
          No - I have not, though it looks like they will display whatever sting I would put in there - what I need to do is display the return success message from mailchimp... sad

          And now, back to the original post, I still need to post some form variables to a snippet... How is this done?

          -thanks
          -sean
            *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

            Sean Kimball CLP, CLS.
            Technical Director / Sr. Developer | BigBlock Studios
            ._______________________________________________.
            Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
            27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
            phone/fax: 905-426-5525
            • 28042 ☆ A M B ☆
            • 24,524 Posts
              Studying MODX in the desert - http://sottwell.com
              Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
              Join the Slack Community - http://modx.org
              • 26503
              • 620 Posts
              Quote from: sottwell at May 30, 2011, 09:35 PM

              You’ll need to use their API.

              http://apidocs.mailchimp.com/rtfm/
              http://apidocs.mailchimp.com/downloads/#examples

              Hi;

              I do have the mailchimp integration working perfectly.
              I have another form on a different page that I need to pass the form variables to a snippet... can’t figure out for the life of me how to do that!

              -sean
                *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                Sean Kimball CLP, CLS.
                Technical Director / Sr. Developer | BigBlock Studios
                ._______________________________________________.
                Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                phone/fax: 905-426-5525