Plugin Directory

Changeset 1970668


Ignore:
Timestamp:
11/08/2018 02:44:39 AM (7 years ago)
Author:
Soben
Message:

Prepping 4.1.1 for launch

Location:
gravityforms-hubspot
Files:
8 edited
1 copied

Legend:

Unmodified
Added
Removed
  • gravityforms-hubspot/branches/dev/gravityforms-hubspot.php

    r1881519 r1970668  
    44        Plugin URI: http://bigsea.co/
    55        Description: Easily integrate your Gravity Forms with HubSpot forms! Match up field-for-field so you can harness the power of HubSpot.
    6         Version: 4.0
     6        Version: 4.1.1
    77        Author: Big Sea
    88        Author URI: http://bigsea.co
     
    1212    define('GF_HUBSPOT_BASENAME', plugin_basename(__FILE__));
    1313    define('GF_HUBSPOT_PATH', WP_PLUGIN_DIR . "/" . basename(dirname(__FILE__)) . "/");
    14     define('GF_HUBSPOT_VERSION', '4.0');
     14    define('GF_HUBSPOT_VERSION', '4.1.1');
    1515    if ( !defined('GF_HUBSPOT_DEBUG') ) define('GF_HUBSPOT_DEBUG', false);
    1616
  • gravityforms-hubspot/branches/dev/readme.txt

    r1881657 r1970668  
    11=== HubSpot for Gravity Forms ===
    2 Contributors: Big Sea, Soben, bloqhead
     2Contributors: Big Sea, Soben
    33Donate link: http://bigsea.co/
    44Tags: hubspot, gravity, forms, submit, submission, lead, api, gravity forms
    55Requires at least: 3.5
    66Tested up to: 4.9.6
    7 Stable tag: 4.0
     7Stable tag: 4.1.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6969== Changelog ==
    7070
     71= 4.1.1 =
     72* [FIX] Modification of strok, via adammichaelroach
     73
     74= 4.1 =
     75* [UPDATE] Improved "enumeration" field type support. Now more properly handles Radio, Boolean Checkboxes (aka 'Single Checkbox'), and Checkboxes fields from HubSpot with more accuracy.
     76* [UPDATE] HubSpot call more accurately sends the current page of the submission (thanks, Josh Allen @cirkut)
     77
     78= 4.0.1 =
     79* [NEW] New Filters: `gf_hubspot_process_success` and `gf_hubspot_process_failure` actions, as well as `gf_hubspot_data_single` filter for modifying a value on a single field basis.
     80* [DEPRECATION] `gf_hubspot_data_outgoing` in favor of `gf_hubspot_data_object` ... both will remain in the code.
     81
    7182= 4.0 =
    72 * [New] Support for "File Upload" field in Gravity Forms. Takes the resulting upload URLs and send them to HubSpot in a semi-colon delimited list.
    73 * [New] `apply_filters( 'gf_hubspot_conditional_not_met', false, $feed, $entry, $form);` Allows you to skip the feed on programmatic conditions.
    74 * [New] Conditional Logic now possible during feed management
     83* [NEW] Support for "File Upload" field in Gravity Forms. Takes the resulting upload URLs and send them to HubSpot in a semi-colon delimited list.
     84* [NEW] `apply_filters( 'gf_hubspot_conditional_not_met', false, $feed, $entry, $form);` Allows you to skip the feed on programmatic conditions.
     85* [NEW] Conditional Logic now possible during feed management
    7586* [NOTICE] Redirections set in HubSpot upon success can cause conflicts. We are trying to show a heads up now to make sure you check your forms :)
    7687
  • gravityforms-hubspot/branches/dev/src/Base.php

    r1729548 r1970668  
    207207            'hutk'      => $hubspotutk,
    208208            'ipAddress' => $ip_addr,
    209             'pageUrl'   => apply_filters( 'gf_hubspot_context_url', site_url() ),
    210             'pageName'  => apply_filters( 'gf_hubspot_context_name', rgars($form, 'title') ),
     209            'pageUrl'   => apply_filters( 'gf_hubspot_context_url', site_url(strtok($_SERVER['REQUEST_URI'], '?')) ),
     210            'pageName'  => apply_filters( 'gf_hubspot_context_name', $this->getValue($form, 'title') ),
    211211        );
    212         if ( rgars ( $feed, 'meta/disableCookie' ) == 1 ) {
     212        if ( $this->getValue($feed, 'meta/disableCookie') == 1 ) {
    213213            unset($hs_context['hutk']);
    214214        }
     
    242242        return $formData;
    243243    } // function
     244
     245     /**
     246        COMMON
     247     */
     248    // rgars is a pain when my trying to debug with existing data, this is to override that, and it's redundant for checks
     249    protected function getValue($data, $field)
     250    {
     251        $data = (array)$data;
     252
     253        if (function_exists('rgars') && rgars($feed, 'meta/formID')) {
     254            return rgars($feed, 'meta/formID');
     255        }
     256
     257        $fieldArray = explode('/', $field);
     258        if (isset($data[$fieldArray[0]])) {
     259            $data = (array)$data[$fieldArray[0]];
     260
     261            if (count($fieldArray) == 1) {
     262                if (is_array($data)) {
     263                    return $data[0];
     264                }
     265               
     266                return $data;
     267            }
     268
     269            return $this->getValue($data, implode('/', array_slice($fieldArray, 1)));
     270        }
     271
     272        return '';
     273    }
    244274} // class
  • gravityforms-hubspot/branches/dev/src/GF_HubSpot.php

    r1881519 r1970668  
    107107
    108108        // Let's get the HubSpot Form!
    109         $form_id = rgars ( $feed, 'meta/formID' );
     109        $form_id = $this->getValue($feed, 'meta/formID');
    110110        $hubspot_form = $this->_getForm( $form_id );
     111        if (!is_object($hubspot_form) || !isset($hubspot_form->name)) {
     112            Tracking::log(__METHOD__ . '(): Invalid HubSpot Form "'.$form_id.'"');
     113            $this->add_feed_error(
     114                'Invalid HubSpot Form "'.$form_id.'"',
     115                $feed,
     116                $entry,
     117                $form
     118            );
     119            return;
     120        }
    111121       
    112122        // We are definitely in a good ground moving forward!
    113123        Tracking::log(__METHOD__ . '(): Feed Processing for Form "'.$hubspot_form->name.'" ('.$form_id.')');
    114124
    115         $fieldMap = $this->get_field_map_fields( $feed, 'fieldMap' );
     125        $feedFieldMap = $this->get_field_map_fields( $feed, 'fieldMap' );
    116126
    117127        $data_to_hubspot = array ();
    118128        foreach ( $hubspot_form->formFieldGroups as $fieldGroup ) {
    119             foreach ($fieldGroup->fields as $field) {
    120                 if ( !isset ( $fieldMap[$field->name] ) ) {
     129            foreach ($fieldGroup->fields as $hubspotField) {
     130                if ( !isset ( $feedFieldMap[$hubspotField->name] ) ) {
    121131                    continue;
    122132                }
    123133
    124                 $gf_field = \GFFormsModel::get_field( $form, $fieldMap[$field->name]);
    125 
    126                 $gf_field_value = $this->get_field_value( $form, $entry, $fieldMap[$field->name] );
    127                 if ( $field->required && !$gf_field_value ) {
    128                     Tracking::log(__METHOD__ . '(): Required field "'.$field->label.'" missing.', $field, $gf_field_value);
     134                $gravityformsField = \GFFormsModel::get_field( $form, $feedFieldMap[$hubspotField->name]);
     135
     136                $gravityformsField_value = $this->get_field_value( $form, $entry, $feedFieldMap[$hubspotField->name] );
     137                if ( $hubspotField->required && !$gravityformsField_value ) {
     138                    Tracking::log(__METHOD__ . '(): Required field "'.$hubspotField->label.'" missing.', $hubspotField, $gravityformsField_value);
    129139                    $this->add_feed_error(
    130                         'Required field "'.$field->label.'" for form "'.$hubspot_form->name.'" ['.$form_id.'] missing.',
     140                        'Required field "'.$hubspotField->label.'" for form "'.$hubspot_form->name.'" ['.$form_id.'] missing.',
    131141                        $feed,
    132142                        $entry,
     
    136146                }
    137147
    138                 $data_to_hubspot[$field->name] = $this->_get_field_formatted_for_hubspot($field->type, $gf_field_value, $gf_field);
     148                $currentDataParsed = $this->_get_field_formatted_for_hubspot($hubspotField, $gravityformsField_value, $gravityformsField);
     149                $data_to_hubspot[$hubspotField->name] = apply_filters('gf_hubspot_data_single', $currentDataParsed, $hubspotField, $feed, $entry, $form);
    139150            }
    140151        }
    141152       
    142153        $data_to_hubspot = apply_filters( 'gf_hubspot_data_outgoing', $data_to_hubspot, $form, $feed );
     154        $data_to_hubspot = apply_filters( 'gf_hubspot_data_object', $data_to_hubspot, $form, $feed );
    143155
    144156        // With all of the data organized now, let's get the HubSpot call ready.
     
    147159        // Try to send the form.
    148160        try {
     161            do_action('gf_hubspot_process_before_send');
     162
    149163            $result = $this->hubspot->forms()->submit($this->getPortalID(), $form_id, $data_to_hubspot);
    150164            $status_code = $result->getStatusCode();
     
    157171
    158172                Tracking::log(__METHOD__ . '(): Form Successfully submitted ['.$form_id.']', $data_to_hubspot);
     173                $this->log_debug('HubSpot accepted the form submission.');
     174                do_action('gf_hubspot_process_success', $data_to_hubspot, $form, $feed);
    159175                return;
    160176            }
     
    164180            $this->add_feed_error(
    165181                'HubSpot rejected the submission with an error '.$status_code.' for "'.$hubspot_form->name.'" ['.$form_id.'].',
    166                 $feed, 
     182                $feed,
    167183                $entry,
    168184                $form
     
    177193            );
    178194        }
     195
     196        do_action('gf_hubspot_process_failure', $data_to_hubspot, $form, $feed);
    179197    } // function
    180198
     
    305323                    'type'           => 'checkbox',
    306324                    'choices'        => array(
    307                                          array(
    308                                              'label'         => 'Disable Cookie Tracking',
    309                                              'name'          => 'disableCookie',
    310                                              'tooltip'       => '<h6>'. __( 'Disable Cookie', 'gravityforms-hubspot' ) .'</h6>' . __( 'When disabled, every submission from the same browser creates a new contact.', 'gravityforms-hubspot' ),
    311                                              'default_value' => 0,
    312 
    313                                          ),
    314                                     )
     325                                            array(
     326                                                'label'         => 'Disable Cookie Tracking',
     327                                                'name'          => 'disableCookie',
     328                                                'tooltip'       => '<h6>'. __( 'Disable Cookie', 'gravityforms-hubspot' ) .'</h6>' . __( 'When disabled, every submission from the same browser creates a new contact.', 'gravityforms-hubspot' ),
     329                                                'default_value' => 0,
     330
     331                                            ),
     332                                        )
    315333                )
    316334            )
     
    407425     */
    408426    public function get_column_value_formID( $feed ) {
    409         $form_details = $this->_getForm( rgars( $feed, 'meta/formID' ) );
     427        $form_details = $this->_getForm( $this->getValue( $feed, 'meta/formID' ) );
    410428
    411429        return isset($form_details->name) ? $form_details->name : 'Form Not Found';
     
    458476        if ( is_object($response) && is_array($response->formFieldGroups) ) {
    459477            foreach ( $response->formFieldGroups as $fieldGroup ) {
    460                 foreach ($fieldGroup->fields as $field) {
    461                     $field_label = $field->name;
    462                     if (trim($field->label) != '') {
    463                         $field_label = $field->label;
     478                foreach ($fieldGroup->fields as $hubspotField) {
     479                    $hubspotField_label = $hubspotField->name;
     480                    if (trim($hubspotField->label) != '') {
     481                        $hubspotField_label = $hubspotField->label;
    464482                    }
    465483                    $output[] = array (
    466                         'label'     => $field_label,
    467                         'name'      => $field->name,
    468                         'required'  => $field->required,
    469                         'value'     => $field->name,
     484                        'label'     => $hubspotField_label,
     485                        'name'      => $hubspotField->name,
     486                        'required'  => $hubspotField->required,
     487                        'value'     => $hubspotField->name,
    470488                    );
    471489                }
     
    481499
    482500        // Posted Settings override the Feed Setting.
    483         if ( $form_id = rgars($posted_settings, 'formID') ) {
     501        if ( $form_id = $this->getValue($posted_settings, 'formID') ) {
    484502            // We have a POST setting
    485503            return $form_id;
    486504        }
    487505
    488         if ( $form_id = rgars($feed, 'meta/formID') ) {
     506        if ( $form_id = $this->getValue($feed, 'meta/formID') ) {
    489507            // We have a saved setting
    490508            return $form_id;
     
    495513
    496514
    497     private function _get_field_formatted_for_hubspot ( $hs_field_type, $data, $gf_field ) {
    498         $data = $this->preParseGravityFormData($data, $gf_field);
    499 
    500         switch ( $hs_field_type ) {
     515    private function _get_field_formatted_for_hubspot ( $hubspotField, $providedInput, $gravityformsField ) {
     516        $providedInput = $this->preParseGravityFormData($providedInput, $hubspotField, $gravityformsField);
     517
     518        switch ( $hubspotField->type ) {
    501519            case 'date' :
    502                 return strtotime($data) * 1000;
    503                 break;
     520                return strtotime($providedInput) * 1000;
    504521            case 'enumeration' :
    505                 // We're expecting multiple pieces of data
    506                 if ( !is_array( $data ) ) {
    507                     $data = explode(', ', $data);
    508                     foreach ( $data as &$content ) {
    509                         $content = trim($content);
    510                     }
     522                switch ($hubspotField->fieldType) {
     523                    case 'booleancheckbox' :
     524                        if ($providedInput != '') {
     525                            return 'true';
     526                        }
     527                        return 'false';
     528                    case 'radio' :
     529                        return $providedInput;
     530                    default :
     531                        // We're expecting multiple pieces of data
     532                        if ( !is_array( $providedInput ) ) {
     533                            $providedInput = explode(', ', $providedInput);
     534                            foreach ( $providedInput as &$content ) {
     535                                $content = trim($content);
     536                            }
     537                        }
     538                        return implode(';', $providedInput);
    511539                }
    512 
    513                 return implode(';', $data);
    514                 break;
    515540            default :
    516                 return $data;
     541                return $providedInput;
    517542        }
    518543    } // function
     
    524549     *      In this case, we're converting the Field type into a semi-colon separated string.
    525550     */
    526     private function preParseGravityFormData($data, $gf_field)
     551    private function preParseGravityFormData($data, $gravityformsField)
    527552    {
    528         // Currently does nothing. We have no special situations to worry about.
     553        // Currently does nothing. We have no special situations to worry about, yet.
    529554
    530555        return $data;
  • gravityforms-hubspot/tags/4.1.1/gravityforms-hubspot.php

    r1881519 r1970668  
    44        Plugin URI: http://bigsea.co/
    55        Description: Easily integrate your Gravity Forms with HubSpot forms! Match up field-for-field so you can harness the power of HubSpot.
    6         Version: 4.0
     6        Version: 4.1.1
    77        Author: Big Sea
    88        Author URI: http://bigsea.co
     
    1212    define('GF_HUBSPOT_BASENAME', plugin_basename(__FILE__));
    1313    define('GF_HUBSPOT_PATH', WP_PLUGIN_DIR . "/" . basename(dirname(__FILE__)) . "/");
    14     define('GF_HUBSPOT_VERSION', '4.0');
     14    define('GF_HUBSPOT_VERSION', '4.1.1');
    1515    if ( !defined('GF_HUBSPOT_DEBUG') ) define('GF_HUBSPOT_DEBUG', false);
    1616
  • gravityforms-hubspot/tags/4.1.1/readme.txt

    r1881657 r1970668  
    11=== HubSpot for Gravity Forms ===
    2 Contributors: Big Sea, Soben, bloqhead
     2Contributors: Big Sea, Soben
    33Donate link: http://bigsea.co/
    44Tags: hubspot, gravity, forms, submit, submission, lead, api, gravity forms
    55Requires at least: 3.5
    66Tested up to: 4.9.6
    7 Stable tag: 4.0
     7Stable tag: 4.1.1
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    6969== Changelog ==
    7070
     71= 4.1.1 =
     72* [FIX] Modification of strok, via adammichaelroach
     73
     74= 4.1 =
     75* [UPDATE] Improved "enumeration" field type support. Now more properly handles Radio, Boolean Checkboxes (aka 'Single Checkbox'), and Checkboxes fields from HubSpot with more accuracy.
     76* [UPDATE] HubSpot call more accurately sends the current page of the submission (thanks, Josh Allen @cirkut)
     77
     78= 4.0.1 =
     79* [NEW] New Filters: `gf_hubspot_process_success` and `gf_hubspot_process_failure` actions, as well as `gf_hubspot_data_single` filter for modifying a value on a single field basis.
     80* [DEPRECATION] `gf_hubspot_data_outgoing` in favor of `gf_hubspot_data_object` ... both will remain in the code.
     81
    7182= 4.0 =
    72 * [New] Support for "File Upload" field in Gravity Forms. Takes the resulting upload URLs and send them to HubSpot in a semi-colon delimited list.
    73 * [New] `apply_filters( 'gf_hubspot_conditional_not_met', false, $feed, $entry, $form);` Allows you to skip the feed on programmatic conditions.
    74 * [New] Conditional Logic now possible during feed management
     83* [NEW] Support for "File Upload" field in Gravity Forms. Takes the resulting upload URLs and send them to HubSpot in a semi-colon delimited list.
     84* [NEW] `apply_filters( 'gf_hubspot_conditional_not_met', false, $feed, $entry, $form);` Allows you to skip the feed on programmatic conditions.
     85* [NEW] Conditional Logic now possible during feed management
    7586* [NOTICE] Redirections set in HubSpot upon success can cause conflicts. We are trying to show a heads up now to make sure you check your forms :)
    7687
  • gravityforms-hubspot/tags/4.1.1/src/Base.php

    r1729548 r1970668  
    207207            'hutk'      => $hubspotutk,
    208208            'ipAddress' => $ip_addr,
    209             'pageUrl'   => apply_filters( 'gf_hubspot_context_url', site_url() ),
    210             'pageName'  => apply_filters( 'gf_hubspot_context_name', rgars($form, 'title') ),
     209            'pageUrl'   => apply_filters( 'gf_hubspot_context_url', site_url(strtok($_SERVER['REQUEST_URI'], '?')) ),
     210            'pageName'  => apply_filters( 'gf_hubspot_context_name', $this->getValue($form, 'title') ),
    211211        );
    212         if ( rgars ( $feed, 'meta/disableCookie' ) == 1 ) {
     212        if ( $this->getValue($feed, 'meta/disableCookie') == 1 ) {
    213213            unset($hs_context['hutk']);
    214214        }
     
    242242        return $formData;
    243243    } // function
     244
     245     /**
     246        COMMON
     247     */
     248    // rgars is a pain when my trying to debug with existing data, this is to override that, and it's redundant for checks
     249    protected function getValue($data, $field)
     250    {
     251        $data = (array)$data;
     252
     253        if (function_exists('rgars') && rgars($feed, 'meta/formID')) {
     254            return rgars($feed, 'meta/formID');
     255        }
     256
     257        $fieldArray = explode('/', $field);
     258        if (isset($data[$fieldArray[0]])) {
     259            $data = (array)$data[$fieldArray[0]];
     260
     261            if (count($fieldArray) == 1) {
     262                if (is_array($data)) {
     263                    return $data[0];
     264                }
     265               
     266                return $data;
     267            }
     268
     269            return $this->getValue($data, implode('/', array_slice($fieldArray, 1)));
     270        }
     271
     272        return '';
     273    }
    244274} // class
  • gravityforms-hubspot/tags/4.1.1/src/GF_HubSpot.php

    r1881519 r1970668  
    107107
    108108        // Let's get the HubSpot Form!
    109         $form_id = rgars ( $feed, 'meta/formID' );
     109        $form_id = $this->getValue($feed, 'meta/formID');
    110110        $hubspot_form = $this->_getForm( $form_id );
     111        if (!is_object($hubspot_form) || !isset($hubspot_form->name)) {
     112            Tracking::log(__METHOD__ . '(): Invalid HubSpot Form "'.$form_id.'"');
     113            $this->add_feed_error(
     114                'Invalid HubSpot Form "'.$form_id.'"',
     115                $feed,
     116                $entry,
     117                $form
     118            );
     119            return;
     120        }
    111121       
    112122        // We are definitely in a good ground moving forward!
    113123        Tracking::log(__METHOD__ . '(): Feed Processing for Form "'.$hubspot_form->name.'" ('.$form_id.')');
    114124
    115         $fieldMap = $this->get_field_map_fields( $feed, 'fieldMap' );
     125        $feedFieldMap = $this->get_field_map_fields( $feed, 'fieldMap' );
    116126
    117127        $data_to_hubspot = array ();
    118128        foreach ( $hubspot_form->formFieldGroups as $fieldGroup ) {
    119             foreach ($fieldGroup->fields as $field) {
    120                 if ( !isset ( $fieldMap[$field->name] ) ) {
     129            foreach ($fieldGroup->fields as $hubspotField) {
     130                if ( !isset ( $feedFieldMap[$hubspotField->name] ) ) {
    121131                    continue;
    122132                }
    123133
    124                 $gf_field = \GFFormsModel::get_field( $form, $fieldMap[$field->name]);
    125 
    126                 $gf_field_value = $this->get_field_value( $form, $entry, $fieldMap[$field->name] );
    127                 if ( $field->required && !$gf_field_value ) {
    128                     Tracking::log(__METHOD__ . '(): Required field "'.$field->label.'" missing.', $field, $gf_field_value);
     134                $gravityformsField = \GFFormsModel::get_field( $form, $feedFieldMap[$hubspotField->name]);
     135
     136                $gravityformsField_value = $this->get_field_value( $form, $entry, $feedFieldMap[$hubspotField->name] );
     137                if ( $hubspotField->required && !$gravityformsField_value ) {
     138                    Tracking::log(__METHOD__ . '(): Required field "'.$hubspotField->label.'" missing.', $hubspotField, $gravityformsField_value);
    129139                    $this->add_feed_error(
    130                         'Required field "'.$field->label.'" for form "'.$hubspot_form->name.'" ['.$form_id.'] missing.',
     140                        'Required field "'.$hubspotField->label.'" for form "'.$hubspot_form->name.'" ['.$form_id.'] missing.',
    131141                        $feed,
    132142                        $entry,
     
    136146                }
    137147
    138                 $data_to_hubspot[$field->name] = $this->_get_field_formatted_for_hubspot($field->type, $gf_field_value, $gf_field);
     148                $currentDataParsed = $this->_get_field_formatted_for_hubspot($hubspotField, $gravityformsField_value, $gravityformsField);
     149                $data_to_hubspot[$hubspotField->name] = apply_filters('gf_hubspot_data_single', $currentDataParsed, $hubspotField, $feed, $entry, $form);
    139150            }
    140151        }
    141152       
    142153        $data_to_hubspot = apply_filters( 'gf_hubspot_data_outgoing', $data_to_hubspot, $form, $feed );
     154        $data_to_hubspot = apply_filters( 'gf_hubspot_data_object', $data_to_hubspot, $form, $feed );
    143155
    144156        // With all of the data organized now, let's get the HubSpot call ready.
     
    147159        // Try to send the form.
    148160        try {
     161            do_action('gf_hubspot_process_before_send');
     162
    149163            $result = $this->hubspot->forms()->submit($this->getPortalID(), $form_id, $data_to_hubspot);
    150164            $status_code = $result->getStatusCode();
     
    157171
    158172                Tracking::log(__METHOD__ . '(): Form Successfully submitted ['.$form_id.']', $data_to_hubspot);
     173                $this->log_debug('HubSpot accepted the form submission.');
     174                do_action('gf_hubspot_process_success', $data_to_hubspot, $form, $feed);
    159175                return;
    160176            }
     
    164180            $this->add_feed_error(
    165181                'HubSpot rejected the submission with an error '.$status_code.' for "'.$hubspot_form->name.'" ['.$form_id.'].',
    166                 $feed, 
     182                $feed,
    167183                $entry,
    168184                $form
     
    177193            );
    178194        }
     195
     196        do_action('gf_hubspot_process_failure', $data_to_hubspot, $form, $feed);
    179197    } // function
    180198
     
    305323                    'type'           => 'checkbox',
    306324                    'choices'        => array(
    307                                          array(
    308                                              'label'         => 'Disable Cookie Tracking',
    309                                              'name'          => 'disableCookie',
    310                                              'tooltip'       => '<h6>'. __( 'Disable Cookie', 'gravityforms-hubspot' ) .'</h6>' . __( 'When disabled, every submission from the same browser creates a new contact.', 'gravityforms-hubspot' ),
    311                                              'default_value' => 0,
    312 
    313                                          ),
    314                                     )
     325                                            array(
     326                                                'label'         => 'Disable Cookie Tracking',
     327                                                'name'          => 'disableCookie',
     328                                                'tooltip'       => '<h6>'. __( 'Disable Cookie', 'gravityforms-hubspot' ) .'</h6>' . __( 'When disabled, every submission from the same browser creates a new contact.', 'gravityforms-hubspot' ),
     329                                                'default_value' => 0,
     330
     331                                            ),
     332                                        )
    315333                )
    316334            )
     
    407425     */
    408426    public function get_column_value_formID( $feed ) {
    409         $form_details = $this->_getForm( rgars( $feed, 'meta/formID' ) );
     427        $form_details = $this->_getForm( $this->getValue( $feed, 'meta/formID' ) );
    410428
    411429        return isset($form_details->name) ? $form_details->name : 'Form Not Found';
     
    458476        if ( is_object($response) && is_array($response->formFieldGroups) ) {
    459477            foreach ( $response->formFieldGroups as $fieldGroup ) {
    460                 foreach ($fieldGroup->fields as $field) {
    461                     $field_label = $field->name;
    462                     if (trim($field->label) != '') {
    463                         $field_label = $field->label;
     478                foreach ($fieldGroup->fields as $hubspotField) {
     479                    $hubspotField_label = $hubspotField->name;
     480                    if (trim($hubspotField->label) != '') {
     481                        $hubspotField_label = $hubspotField->label;
    464482                    }
    465483                    $output[] = array (
    466                         'label'     => $field_label,
    467                         'name'      => $field->name,
    468                         'required'  => $field->required,
    469                         'value'     => $field->name,
     484                        'label'     => $hubspotField_label,
     485                        'name'      => $hubspotField->name,
     486                        'required'  => $hubspotField->required,
     487                        'value'     => $hubspotField->name,
    470488                    );
    471489                }
     
    481499
    482500        // Posted Settings override the Feed Setting.
    483         if ( $form_id = rgars($posted_settings, 'formID') ) {
     501        if ( $form_id = $this->getValue($posted_settings, 'formID') ) {
    484502            // We have a POST setting
    485503            return $form_id;
    486504        }
    487505
    488         if ( $form_id = rgars($feed, 'meta/formID') ) {
     506        if ( $form_id = $this->getValue($feed, 'meta/formID') ) {
    489507            // We have a saved setting
    490508            return $form_id;
     
    495513
    496514
    497     private function _get_field_formatted_for_hubspot ( $hs_field_type, $data, $gf_field ) {
    498         $data = $this->preParseGravityFormData($data, $gf_field);
    499 
    500         switch ( $hs_field_type ) {
     515    private function _get_field_formatted_for_hubspot ( $hubspotField, $providedInput, $gravityformsField ) {
     516        $providedInput = $this->preParseGravityFormData($providedInput, $hubspotField, $gravityformsField);
     517
     518        switch ( $hubspotField->type ) {
    501519            case 'date' :
    502                 return strtotime($data) * 1000;
    503                 break;
     520                return strtotime($providedInput) * 1000;
    504521            case 'enumeration' :
    505                 // We're expecting multiple pieces of data
    506                 if ( !is_array( $data ) ) {
    507                     $data = explode(', ', $data);
    508                     foreach ( $data as &$content ) {
    509                         $content = trim($content);
    510                     }
     522                switch ($hubspotField->fieldType) {
     523                    case 'booleancheckbox' :
     524                        if ($providedInput != '') {
     525                            return 'true';
     526                        }
     527                        return 'false';
     528                    case 'radio' :
     529                        return $providedInput;
     530                    default :
     531                        // We're expecting multiple pieces of data
     532                        if ( !is_array( $providedInput ) ) {
     533                            $providedInput = explode(', ', $providedInput);
     534                            foreach ( $providedInput as &$content ) {
     535                                $content = trim($content);
     536                            }
     537                        }
     538                        return implode(';', $providedInput);
    511539                }
    512 
    513                 return implode(';', $data);
    514                 break;
    515540            default :
    516                 return $data;
     541                return $providedInput;
    517542        }
    518543    } // function
     
    524549     *      In this case, we're converting the Field type into a semi-colon separated string.
    525550     */
    526     private function preParseGravityFormData($data, $gf_field)
     551    private function preParseGravityFormData($data, $gravityformsField)
    527552    {
    528         // Currently does nothing. We have no special situations to worry about.
     553        // Currently does nothing. We have no special situations to worry about, yet.
    529554
    530555        return $data;
Note: See TracChangeset for help on using the changeset viewer.