From: Steve Sutton Date: Fri, 8 Jul 2016 19:30:12 +0000 (-0400) Subject: bug fix X-Git-Tag: v1.0.0^2~34 X-Git-Url: http://cvs2.gaslightmedia.com/gitweb/?a=commitdiff_plain;h=aa490785b5940f423cc7330309797af03baa1449;p=WP-Plugins%2Fglm-member-db-leads.git bug fix Was adding incorrect interest id to the table. Can't use the forms id's they're based on the choice numbers. --- diff --git a/setup/frontHooks.php b/setup/frontHooks.php index 2596cee..3f73913 100644 --- a/setup/frontHooks.php +++ b/setup/frontHooks.php @@ -73,7 +73,7 @@ add_filter( 'gform_pre_render', function( $form ) { return $form; }); add_action( 'gform_after_submission', function( $entry, $form ){ - //echo '
$entry: ' . print_r($entry, true) . '
'; + $leads_fields = array(); $mapped_keys = array( 'fname', 'lname', @@ -88,12 +88,21 @@ add_action( 'gform_after_submission', function( $entry, $form ){ 'phone', 'phone2', 'fax', + 'mail_ok', + 'member_ok', ); // have to go through the $form array to see what field we need from post $glm_leads_entry = array(); if ( $form['fields'] ) { foreach ( $form['fields'] as $field ) { switch ( $field['type'] ) { + case 'checkbox': + if ( in_array( $field['inputName'], $mapped_keys ) ) { + if ( isset( $_POST['input_' . $field['id'] . '_1'] ) && $_POST['input_' . $field['id'] . '_1'] ) { + $glm_leads_entry[$field['inputName']] = 1; + } + } + break; case 'website': case 'phone': case 'email': @@ -113,14 +122,12 @@ add_action( 'gform_after_submission', function( $entry, $form ){ } break; case 'leads': - $leads_fields = array(); foreach ( $_POST as $key => $value ) { if ( preg_match( '/input_' . $field['id'] . '_(\d*)/', $key, $matches ) ) { // grab the final digit - $leads_fields[$matches[1]] = $value; + $leads_fields[] = $value; } } - //$glm_leads_entry['leads'] = $leads_fields; break; default: break; @@ -150,10 +157,12 @@ add_action( 'gform_after_submission', function( $entry, $form ){ $result = $this->wpdb->insert( GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'leads', // table array( - 'email' => $glm_leads_entry['email'], - 'created' => $entry['date_created'], + 'email' => $glm_leads_entry['email'], + 'created' => $entry['date_created'], + 'mail_ok' => ( $glm_leads_entry['mail_ok'] ) ? 1: 0, + 'member_ok' => ( $glm_leads_entry['member_ok'] ) ? 1: 0, ), // data - array( '%s', '%s' ) // data format + array( '%s', '%s', '%s', '%s' ) // data format ); if ( $result === false ) { die( 'lead error given' ); @@ -207,23 +216,36 @@ add_action( 'gform_after_submission', function( $entry, $form ){ die( 'lead_entry error given' ); } $lead_entry_id = $this->wpdb->insert_id; + + $ints = array(); + $interestsData = new GlmDataInterests( $this->wpdb, $this->config ); + $interests = $interestsData->getList(); + if ( $interests ) { + foreach ( $interests as $interest ) { + $ints[$interest['id']] = $interest['title']; + } + } + //echo '
$interests: ' . print_r($interests, true) . '
'; + //echo '
$ints: ' . print_r($ints, true) . '
'; + //echo '
$leads_fields: ' . print_r($leads_fields, true) . '
'; // create the lead to interest entries // using $leads_fields // first delete any they current have + //echo '
$leads_fields: ' . print_r($leads_fields, true) . '
'; if ( is_array( $leads_fields) && !empty( $leads_fields ) ) { - foreach ( $leads_fields as $interest_id => $interest_val ) { - $this->wpdb->insert( - GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_interests', // table - array( - 'interest_id' => $interest_id, - 'lead_entry_id' => $lead_entry_id - ), // data - array( '%d', '%d' ) // data format - ); + foreach ( $leads_fields as $interest_val ) { + $int_key = array_search( $interest_val, $ints ); + //echo '
$int_key: ' . print_r($int_key, true) . '
'; + if ( $int_key ) { + $this->wpdb->insert( + GLM_MEMBERS_LEADS_PLUGIN_DB_PREFIX . 'lead_interests', // table + array( + 'interest_id' => $int_key, + 'lead_entry_id' => $lead_entry_id + ), // data + array( '%d', '%d' ) // data format + ); + } } } - //echo '
$glm_leads_entry: ' . print_r($glm_leads_entry, true) . '
'; - //echo '
$_POST: ' . print_r($_POST, true) . '
'; - //echo '
$form: ' . print_r($form, true) . '
'; - //exit; }, 10, 2);