We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34017
    • 898 Posts
    Just wanted to say thanks Toby! I was needing to have a form submit to mailChimp and it worked without a hitch. I’ll share the little info I found too.

    To have your function stop the process and give a custom validation error, do:

    eForm document call
    [!yourValidationSnippet? !]
    [!eForm? etc.....  &eFormOnValidate=`my_validation` !]
    

    function my_validation(&$vMsg, &$rMsg) {
      if ($validation_errors != '')
      {
    	$vMsg[] =  $api->errorMessage;
    	return $vMsg;
      }
    
    }
    


    That’s all there is to it to create a custom validation message.
      Chuck the Trukk
      ProWebscape.com :: Nashville-WebDesign.com
      - - - - - - - -
      What are TV's? Here's some info below.
      http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
      http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008
      • 25663 MODX Staff
      • 12,272 Posts
      Hey Chuck, I’d be interested in seeing your MailChimp work ... you’re probably not aware just yet, but MailChimp is the first of several things we love: http://modxcms.com/things-we-love.html
        Ryan Thrash, MODX Co-Founder
        Follow me on Twitter at @rthrash or catch my occasional unofficial thoughts at thrash.me
        • 34017
        • 898 Posts
        I was not aware that you loved mailChimp. Just moved a client from constant contact for it. I would say I love it to. Here’s the code I’ve been working on. It submits the eform to create a new user. If the user is already in the list, it shows an error with an update checkbox so they can update their info if they want.

        <?php
        function mailchimp_signup(&$fields, &$vMsg, &$rMsg){
        
        			$update_button  = '<br/><br/>';
        			$update_button .= 'Would you like to update your information?<br/>';
        			$update_button .= '<input class="checkbox" type="checkbox" name="Update_your_Information[]" value="checked" style="float:left;margin-top:3px;margin-right: 5px;" /> Check the box and click "Update"';
        			$update_button .= '<input class="button_norm" type="submit" value="Update" />';
        
        			$update_success = '<style type="text/css">
        													.wlpeMessage {background: #E6EFC2; color: #529214; border-color: #C6D880;} 
        													.wlpeMessage .error {background: #E6EFC2; color: #529214;}
        													.error_heading {display: none;}
        												</style>';
        												
        	if(!$fields['email']){ 
        		$vMsg[] = '<div class="error">No email address provided</div>';
        		return $vMsg;
        	}
        		
        	if(!preg_match("/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*$/i", $_POST['email'])) {
        		$vMsg[] = '<div class="error">Your email must contain "@" sign and have a "dot something" at the end.</div>';
        		return $vMsg;
        	}
        
        	require_once($snipPath.'MCAPI.class.php');
        	$api = new MCAPI('USERNAME','PASSWORD');
        	
        	// Fetch mailing list id
        	$lists = $api->lists();
        	$list_id = $lists[0]['id']; 
        	// Note: if you have more than one list you'll need to change the $lists[0] array 
        	// (ex: second list would be 1 becaue array start counting from 0)
        
        	// Merge variables are the names of all of the fields your mailing list accepts
        	// Ex: first name is by default FNAME
        	// You can define the names of each merge variable in Lists > click the desired list > list settings > Merge tags for personalization
        	// Pass merge values to the API in an array as follows
        	$mergeVars = array(
        											'TITLE'				=> $fields['title'],
        											'FNAME'				=> $fields['First_Name'],
        											'LNAME'				=> $fields['Last_Name'],
        											'ADDRESS_1'		=> $fields['mailing_address'],
        											'ADDRESS_2'		=> $fields['mailing_address2'],
        											'CITY'				=> $fields['city'],
        											'STATE'				=> $fields['state'],
        											'ZIPCODE'			=> $fields['zip'],
        											'PHONE'				=> $fields['phone'],
        											'MOBILE_PHO'=> $fields['cell_phone'],
        											'FAX'					=> $fields['fax']
        										);
        
        	if($api->listSubscribe($list_id, $fields['email'], $mergeVars) === true) {
        		// It worked!	
        		//There's no reason to have this here really.
        		$success =  '<div class="success">Success! Check your email to confirm sign up.</div>';
        	}else{
        		// An error ocurred, return error message	
        		if (isset($fields['Update_your_Information']))
        		{
        			//if they check update profile
        			if($api->listUpdateMember($list_id, $fields['email'], $mergeVars) === true)
        			{
        				echo $update_success;	//reset colors for error form. i didnt want them to see the welcome to signup page. They've already signed up!
        				$vMsg = '';
        				$vMsg[] =  'Your profile has been updated';
        				return $vMsg;
        			//There is an error with the update. show update button because (1) they are already on the list, and (2) they just tried to signup again
        			} else {
        				$vMsg[] =  $api->errorMessage . $update_button;
        				return $vMsg;
        			}
        		// There is an error with the submission. Maybe they are already on the list. If so, we show them the update checkbox
        		}	else {
        			$vMsg[] =  $api->errorMessage . $update_button;
        			return $vMsg;
        		}
        	}
        }
        ?>
        


        If I use it again, I’d probably make it use chunkie (for either chunk or file for the templating) and add some parameters if needed. It’s a quick start.
          Chuck the Trukk
          ProWebscape.com :: Nashville-WebDesign.com
          - - - - - - - -
          What are TV's? Here's some info below.
          http://modxcms.com/forums/index.php/topic,21081.msg159009.html#msg1590091
          http://modxcms.com/forums/index.php/topic,14957.msg97008.html#msg97008