We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 34017
    • 898 Posts
    I am adding the new user details to Constant Contact via their API when a user signs up. I am having problems with the plugin. I tried the below with both $NewUser[variable] and $user[variable]. Do you have any ideas on this?

    I’ll donate via GPL a snippet I have for using Foxycart downloads on your own server if I can get some help with this.

    Code:
    $e = &$modx->Event;
    switch ($e->name) {
    case "OnWebSaveUser":
    
    			header( "Expires: Mon, 20 Dec 1998 01:00:00 GMT" );
    			header( "Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT" );
       			header( "Cache-Control: no-cache, must-revalidate" );
    			header( "Pragma: no-cache" );
    			
    			$cc_username  = "CONSTANT_CONTACT_USERNAME";
    			$cc_password  = "CONSTANT_CONTACT_PASSWORD";
    			$list_name = 'CONSTANT_CONTACT_EMAIL_LIST';
    			$cc_url = "CONSTANT_CONTACT_URL";
    			
    			// Constant form data
    			$cc_data = "loginName=" . $cc_username;
    			$cc_data .= "&loginPassword=" . $cc_password;
    			$cc_data .= "&ea=" . urlencode(strip_tags($NewUser["email"]));;
    			if (isset($NewUser["first_name"])) $cc_data .= "&First_Name=" . urlencode(strip_tags($NewUser["first_name"]));
    			if (isset($NewUser["middle_name"])) $cc_data .= "&Middle_Name=" . urlencode(strip_tags($NewUser["middle_name"]));
    			if (isset($NewUser["last_name"])) $cc_data .= "&Last_Name=" . urlencode(strip_tags($NewUser["last_name"]));
    			if (isset($NewUser["title"])) $cc_data .= "&Job_Title=" . urlencode(strip_tags($NewUser["title"]));
    			if (isset($NewUser["Company_Name"])) $cc_data .= "&Company_Name=" . urlencode(strip_tags($NewUser["Company_Name"]));
    			if (isset($NewUser["Work_Phone"])) $cc_data .= "&Work_Phone=" . urlencode(strip_tags($NewUser["Work_Phone"]));
    			if (isset($NewUser["phone"])) $cc_data .= "&Home_Phone=" . urlencode(strip_tags($NewUser["phone"]));
    			if (isset($NewUser["address"])) $cc_data .= "&Address_Line_1=" . urlencode(strip_tags($NewUser["address"]));
    			if (isset($NewUser["Address_Line_2"])) $cc_data .= "&Address_Line_2=" . urlencode(strip_tags($NewUser["Address_Line_2"]));
    			if (isset($NewUser["Address_Line_3"])) $cc_data .= "&Address_Line_3=" . urlencode(strip_tags($NewUser["Address_Line_3"]));
    			if (isset($NewUser["city"])) $cc_data .= "&City=" . urlencode(strip_tags($NewUser["city"]));
    			if (isset($NewUser["state"])) $cc_data .= "&State=" . urlencode(strip_tags($NewUser["state"]));
    			if (isset($NewUser["country"])) $cc_data .= "&Country=" . urlencode(strip_tags($NewUser["country"]));
    			if (isset($NewUser["zip"])) $cc_data .= "&Postal_Code=" . urlencode(strip_tags($NewUser["zip"]));
    			if (isset($NewUser["Sub_Postal_Code"])) $cc_data .= "&Sub_Postal_Code=" . urlencode(strip_tags($NewUser["Sub_Postal_Code"]));
    			if (isset($NewUser["Email_Type"])) $cc_data .= "&Email_Type=" . urlencode(strip_tags($NewUser["Email_Type"]));
    			$list_data = "&ic=" . urlencode(strip_tags($list_name));
    
    			//If the form was submitted, and the email is valid, then POST via libcurl
    			$ch = curl_init();    // initialize curl handle
    			curl_setopt($ch, CURLOPT_URL,$cc_url); // set url to post to
    			curl_setopt($ch, CURLOPT_FAILONERROR, 1);
    			curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);// allow redirects
    			curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
    			curl_setopt($ch, CURLOPT_TIMEOUT, 3); // times out after 4s
    			curl_setopt($ch, CURLOPT_POST, 1); // set POST method
    			curl_setopt($ch, CURLOPT_POSTFIELDS, $cc_data . $list_data); // add POST fields
    			$cc_result = curl_exec($ch); // run the whole process
    			curl_close($ch); 
     break;
    default : 
    return; // stop here - this is very important. 
     break;
    }
    

      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
      • 29181
      • 480 Posts
      Did you ever get this working Chuck?

      I need to do something similar within the next 10 days or so.

      Taff
        Adrian Lawley: www.adrianlawley.com
        • 34017
        • 898 Posts
        Taff,

        There are some bugs in WebloginPE so you may want to use the 1.3.1 that Soshite is using.

        The 2 array options you have are:
        //for OnWebSaveUser $this->OnWebSaveUser('new', $NewUser);
        // you either use $new['fields'] or $NewUser['fields']
        
        //for onBeforeWebSaveUser $this->OnBeforeWebSaveUser
        //you use $NewUser['fields']
        


        You may want to create a log of the $NewUser array to see whats available or email the results to you to see what’s happening. But those are the arrays sent to the plugin.

        Let me know how it goes.
          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
          • 29181
          • 480 Posts
          Hey Chuck,
          thanks for the reply. I’m going to try to accomplish this without WLPE. The fields the "normal" web user can be assigned should suffice. And I find the *.processor.php a lot easier to read (and see what the array is using).

          I’ll definitely let you know how it goes.

          Taff
            Adrian Lawley: www.adrianlawley.com
            • 34017
            • 898 Posts
            Yeah I’m not using wlpe for any live sites until it gets a little more stable either. Let me know how your solution goes.
              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
              • 29181
              • 480 Posts
              My objective is a little different to yours. I want to create a web group, create a document group (and assign it to the web group), create a document as a child of a specific document id that only that web group (and the client manager) can see. The template will be a blog type affair so that the client and manager can communicate and send messages on the current situation of their project.

              Using the array of items passed to the OnBeforeWUsrFormSave & OnWebSaveUser events, this has been a breeze (The first one appeared to be a fast way of finding out if the user had already been created or not with the $id).

              I’ll be documenting how my progress goes at http://modxcms.com/forums/index.php/topic,26069.msg159380.html#msg159380

              Hope you managed to get your plugin with this event working...sounds like a lot of fun grin

              Taff
                Adrian Lawley: www.adrianlawley.com