We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 31654
    • 238 Posts
    I need to integrate CampaignMonitor.com with an eForm quote request form.

    I’ve got the subscribe to work every time someone sends an email using eForm. I just need an ’if’ statement (or something like that) to only process the ’add subscription’ when a tickbox is ’selected’

    I would like to have a tick box on the form which will submit the name and email address to CampaignMonitor.com at the same time as sending the quote request email.
    Page it will work on (subscribe tick box not on there yet! ): www.birdgard.com.au/get-a-quote/

    <?php
    //
    // Takes the user from an eForm submission and adds them
    // to the configured MailBuild / CampaignMonitor list.  How to make it go:
    //
    // 1. Set up the configuration variables below.
    // 2. Create a snippet named 'eForm2MailBuild'.
    // 3. On the page with your eForm call, call the eForm2MailBuild snippet before
    //  your eForm call.
    // 4. Modify your eForm call to run a callback function named 'eForm2MailBuild'.
    //
    // In your page, looks something like:
    //
    // [[eForm2MailBuild]]
    // [!eForm? &noemail=`true` &formid=`contact` &eFormOnBeforeMailSent=`eForm2MailBuild` &tpl=`contactform` &thankyou=`contactthanks` !]
    //
    
    
    // ============= Configuration =============
    
    define('MB_API_KEY', '<api_key>'); // Replace <api_key> with your MailBulid API key
    define('MB_LIST_ID', '<list_id>'); // Replace <list_id> with your list ID
    
    // =========== End Configuration ===========
    
    
      function eForm2MailBuild( &$fields )
      {
    
        $params = new stdclass();
        $params->ApiKey = MB_API_KEY;
        $params->ListID = MB_LIST_ID;
        $params->Name = $fields['first_name'].' '.$fields['last_name'];
        $params->Email = $fields['email'];
    
        try {
          $client = new SoapClient("http://api.createsend.com/api/api.asmx?wsdl", array('trace' => 1));
          $result = get_object_vars($client->AddSubscriber($params));   
     
          $resultCode = current($result)->Code;
          $resultMessage = current($result)->Message;
     
          // If not successful
          if ($resultCode > 0) {
            $isError = true;
          }
     
          // The following code produces the entire service request and response. It may be useful for debugging.
       
          print "<pre>\n";
            print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
            print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
            print "</pre>";
           
        }
        catch (SoapFault $e) {
          //mail('[email protected]', 'error processing form', $e->getMessage()); // Uncomment and replace email address if you want to know when something goes wrong.
         // print_r($e); die(); // Uncomment to spit out debugging information and die on error.
        }
    
        return true;
      }
    
    ?>
    


    Many thanks for any help
      Web Development, Web Hosting & Search Engine Marketing by:

      Vitalized | UK
      w. www.vitalized.co.uk

      Website Design | Search Engine Marketing (SEM) | UK MODx web hosting, secure, fast & 100% MODx compatible

      Vitalized | Australia
      w. www.vitalized-australia.com.au

      Website Design | Search Engine Marketing (SEM) | Australian MODx web hosting, secure, fast & 100% MODx compatible
      • 31654
      • 238 Posts
      Think I worked it out... with an if($_POST[’subscribe’] == ’Yes’) before the $params... Open to suggestions for doing it a better way smiley


      <?php
      //
      // Takes the user from an eForm submission and adds them
      // to the configured MailBuild / CampaignMonitor list.  How to make it go:
      //
      // 1. Set up the configuration variables below.
      // 2. Create a snippet named 'eForm2MailBuild'.
      // 3. On the page with your eForm call, call the eForm2MailBuild snippet before
      //  your eForm call.
      // 4. Modify your eForm call to run a callback function named 'eForm2MailBuild'.
      //
      // In your page, looks something like:
      //
      // [[eForm2MailBuild]]
      // [!eForm? &noemail=`true` &formid=`contact` &eFormOnBeforeMailSent=`eForm2MailBuild` &tpl=`contactform` &thankyou=`contactthanks` !]
      //
      
      
      // ============= Configuration =============
      
      define('MB_API_KEY', '<api_key>'); // Replace <api_key> with your MailBulid API key
      define('MB_LIST_ID', '<list_id>'); // Replace <list_id> with your list ID
      
      // =========== End Configuration ===========
      
      
        function eForm2MailBuild( &$fields )
        {
      
      if($_POST['subscribe'] == 'Yes')
      {
      
          $params = new stdclass();
          $params->ApiKey = MB_API_KEY;
          $params->ListID = MB_LIST_ID;
          $params->Name = $fields['first_name'].' '.$fields['last_name'];
          $params->Email = $fields['email'];
      
          try {
            $client = new SoapClient("http://api.createsend.com/api/api.asmx?wsdl", array('trace' => 1));
            $result = get_object_vars($client->AddSubscriber($params));   
       
            $resultCode = current($result)->Code;
            $resultMessage = current($result)->Message;
       
            // If not successful
            if ($resultCode > 0) {
              $isError = true;
            }
       
            // The following code produces the entire service request and response. It may be useful for debugging.
         
            print "<pre>\n";
              print "Request :\n".htmlspecialchars($client->__getLastRequest()) ."\n";
              print "Response:\n".htmlspecialchars($client->__getLastResponse())."\n";
              print "</pre>";
             
          }
          catch (SoapFault $e) {
            //mail('[email protected]', 'error processing form', $e->getMessage()); // Uncomment and replace email address if you want to know when something goes wrong.
           // print_r($e); die(); // Uncomment to spit out debugging information and die on error.
          }
      
          return true;
        }
      }
      ?>
      
        Web Development, Web Hosting & Search Engine Marketing by:

        Vitalized | UK
        w. www.vitalized.co.uk

        Website Design | Search Engine Marketing (SEM) | UK MODx web hosting, secure, fast & 100% MODx compatible

        Vitalized | Australia
        w. www.vitalized-australia.com.au

        Website Design | Search Engine Marketing (SEM) | Australian MODx web hosting, secure, fast & 100% MODx compatible
        • 14617
        • 47 Posts
        I am very interested in this as well...

        I get the following error when trying to use this script:
        Fatal error: Class 'SoapClient' not found in ...


        Is soapclient a class that you are including? Or is it at part of php not supported by my server (mediatemple dv)?

        Anyways - what you are doing is exactly what i need smiley