Plugin Directory

Changeset 1728808


Ignore:
Timestamp:
09/12/2017 04:16:18 PM (8 years ago)
Author:
ohayo-web
Message:

Version 1.1

Location:
mis-leads-contact-form-7/trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • mis-leads-contact-form-7/trunk/includes/class.misleads-cf7.php

    r1724122 r1728808  
    1212   
    1313    private static $i18n_domain;
     14   
     15    # Sino encontramos la presencia de estos campos, deberemos enviar un -1
     16    private static $required_fields = array(
     17            'name', 'surname', 'phone', 'message', 'field_1' );
    1418   
    1519   
     
    6064        add_action( 'misleads_cf7_notices',     array( 'Mis_Leads_CF7', 'admin_notices' ), 10, 2 );
    6165       
     66        // Testing Contact Form Hook
    6267        //add_action( 'wpcf7_before_send_mail',     array( 'Mis_Leads_CF7', 'process_conversion' ) );
    63         add_action( 'wp_footer',                array( 'Mis_Leads_CF7', 'client_process_conversion') );
     68       
     69        // Version 1.0
     70        //add_action( 'wp_footer',              array( 'Mis_Leads_CF7', 'client_process_conversion') );
    6471       
    6572        // Backend Scripts
     
    98105                        'source' => self::$option['source'],
    99106                        'cliente' => self::$option['cliente'],
     107                        'required' => self::$required_fields,
     108                        'debug' => WP_DEBUG,
    100109                        ));
    101110       
     
    205214    public static function process_conversion( $contact_form ){
    206215        $submission = WPCF7_Submission::get_instance();
    207     }
    208     */
     216        echo '<pre>'.print_r($submission,1).'</pre>'; die;
     217    }
     218   
    209219   
    210220    public static function client_process_conversion(){
     
    212222        ?>
    213223        <script>
     224
     225        function ValidateFields( params ){
     226
     227            //console.log(misLeadsCF7.required);
     228            console.log(params);
     229            test = [];
     230
     231            for (var key in misLeadsCF7.required ) {
     232               
     233                if( params[ misLeadsCF7.required[ key ] ] == undefined ){
     234                    console.log('NO EXISTE ' + misLeadsCF7.required[ key ] );
     235                   
     236                    params[ misLeadsCF7.required[ key ] ] == -1;
     237                    test[ misLeadsCF7.required[ key ] ] == -1;
     238                    //test.push( misLeadsCF7.required[ key ] )
     239                }
     240               
     241            }
     242           
     243            console.log( test )
     244            console.log( params )
     245            return params;
     246        }
     247       
    214248        jQuery('.wpcf7-form').submit(function(ev) {
    215249            ev.preventDefault(); // to stop the form from submitting
    216        
     250
     251            var error = false;
    217252            var values = jQuery(this).serializeArray();
    218253            var params = [];
    219254
    220             console.log(values);
    221             /*
    222            
    223             console.log(misLeadsCF7.fields);
    224             console.log(misLeadsCF7.products);
    225             */
    226            
    227255            jQuery.each( values, function( i, field ) {
    228256               
    229257                //console.log( field.name);
    230 
    231258                if( misLeadsCF7.fields[ field.name ] ){
    232259                    params[ misLeadsCF7.fields[ field.name ] ] = field.value;
     
    238265            params['source'] = misLeadsCF7.source;
    239266           
    240             console.log( params );
    241 
     267            //console.log( params );
     268            //  Validamos que los campos requeridos esten incluidos
     269            //params = ValidateFields( params );
     270            //console.log( params );
     271           
    242272            //var str_param = jQuery.param( params, true );
    243273            tmp_param = [];
    244274            for (var key in params) {
    245                 tmp_param.push(key + '=' + encodeURIComponent(params[key]));
     275               
     276                if( params[key] == ''){
     277                    error = true;
     278                }else{
     279                    tmp_param.push(key + '=' + encodeURIComponent(params[key]));   
     280                }
    246281            }
    247 
     282           
    248283            str_param = tmp_param.join('&');
    249             console.log(str_param );
    250 
    251             console.log( 'https://gestiona.misleads.es/'+ misLeadsCF7.cliente +'/api/lead?' + str_param )
    252            
    253             jQuery.ajax({
    254                   type: "GET",
    255                   url: 'https://gestiona.misleads.es/'+ misLeadsCF7.cliente +'/api/lead?' + String( str_param ),
    256                   data: values,
    257                   crossDomain: true,
    258                   dataType: 'jsonp',
    259                   jsonp: false,
    260                   jsonpCallback: false
    261                  
    262                 });
    263            
    264             /* Validations go here */
    265             this.submit(); // If all the validations succeeded
     284           
     285
     286            if(!error){
     287           
     288                console.log( 'https://gestiona.misleads.es/'+ misLeadsCF7.cliente +'/api/lead?' + String( str_param ) )
     289               
     290                jQuery.ajax({
     291                      type: "GET",
     292                      url: 'https://gestiona.misleads.es/'+ misLeadsCF7.cliente +'/api/lead?' + String( str_param ),
     293                      data: values,
     294                      crossDomain: true,
     295                      dataType: 'jsonp',
     296                      jsonp: false,
     297                      jsonpCallback: false
     298                     
     299                    });
     300               
     301                // Validations go here
     302               
     303                //this.submit(); // Envia el formulario 2 veces
     304               
     305            }else{
     306                console.log('Error, campos vacios');
     307                console.log( str_param );
     308            }
    266309           
    267310        });
     
    270313       
    271314    }
     315    */
    272316}
    273317
  • mis-leads-contact-form-7/trunk/js/front.js

    r1724122 r1728808  
    11jQuery(document).ready(function($) {
     2   
     3   
     4    document.addEventListener( 'wpcf7mailsent', function( event ) {
     5        if( misLeadsCF7.debug ) console.log('[MIS LEADS] - SendLead()');
     6        SendLead();
     7    }, false );
     8   
     9   
     10    function SendLead(){
     11       
     12        var values = $('.wpcf7-form').serializeArray();
     13        var params = [];
     14       
     15        $.each( values, function( i, field ) {
     16
     17            if( misLeadsCF7.fields[ field.name ] ){
     18                params[ misLeadsCF7.fields[ field.name ] ] = field.value;
     19            }
     20           
     21        });
     22
     23        params['product'] = misLeadsCF7.products[ window.location.pathname ];
     24        params['source'] = misLeadsCF7.source;
     25       
     26        // Version 2
     27        console.log(params);
     28        params = addRequiredFields( params );
     29        console.log(params);
     30       
     31        tmp_param = [];
     32        for (var key in params) {
     33           
     34//          if( misLeadsCF7.debug ) console.log('[MIS LEADS] - Validating '+ key +' - '+ params[key] );
     35//         
     36//          if( needDefaultValue( key, params[key] ) == true ){
     37//              tmp_param.push(key + '=' + encodeURIComponent( '-1' ));
     38//          }else{
     39//              tmp_param.push(key + '=' + encodeURIComponent(params[key]));
     40//          }
     41           
     42            // Version 1.0
     43            tmp_param.push(key + '=' + encodeURIComponent(params[key]));
     44           
     45        }
     46       
     47        str_param = tmp_param.join('&');
     48       
     49        if( misLeadsCF7.debug ) console.log( 'https://gestiona.misleads.es/'+ misLeadsCF7.cliente +'/api/lead?' + String( str_param ) )
     50       
     51        $.ajax({
     52              type: "GET",
     53              url: 'https://gestiona.misleads.es/'+ misLeadsCF7.cliente +'/api/lead?' + String( str_param ),
     54              data: values,
     55              crossDomain: true,
     56              dataType: 'jsonp',
     57              jsonp: false,
     58              jsonpCallback: false,
     59              success: function(response, status, xhr){
     60                  console.log(response);
     61                  console.log(status);
     62                  console.log(xhr);
     63              },
     64                 
     65            });
     66       
     67    }
     68   
     69    function addRequiredFields( fields ){
     70        // 'name', 'surname', 'phone', 'message', 'field_1'
     71        if( ( fields.indexOf('name') == -1 ) && ( misLeadsCF7.required.indexOf( 'name' ) ) ){
     72            console.log( 'name' + fields.indexOf('name') );
     73            fields['name'] = '-1';
     74        }else if( ( fields.indexOf('surname') == -1 ) && ( misLeadsCF7.required.indexOf( 'surname' ) ) ){
     75            console.log( 'surname' + fields.indexOf('surname') );
     76            fields['field_1'] = '-1';
     77        }else if( ( fields.indexOf('phone') == -1 ) && ( misLeadsCF7.required.indexOf( 'phone' ) ) ){
     78            console.log( 'phone' + fields.indexOf('phone') );
     79            fields['phone'] = '-1';
     80        }else if( ( fields.indexOf('message') == -1 ) && ( misLeadsCF7.required.indexOf( 'message' ) ) ){
     81            console.log( 'message' + fields.indexOf('message') );
     82            fields['message'] = '-1';
     83        }else if( ( fields.indexOf('field_1') == -1 ) && ( misLeadsCF7.required.indexOf( 'field_1' ) ) ){
     84            console.log( 'field_1' + fields.indexOf('field_1') );
     85            fields['field_1'] = '-1';
     86        }
     87       
     88        return fields;
     89    }
     90   
     91    function needDefaultValue( $field, $value ){
     92        //if( params[ misLeadsCF7.required[ key ] ] == undefined ){
     93        if( misLeadsCF7.debug ) console.log( $field + ' IN '+ $value );
     94       
     95        ind = misLeadsCF7.required.indexOf( $field );
     96        indparam = params.indexOf( $field );
     97       
     98        console.log(ind);
     99       
     100        //if( ind !== -1 ) return;
     101       
     102        if( ( indparam != -1) && (ind == -1 ) && !$value ){
     103            if( misLeadsCF7.debug ) console.log( 'No se encuentra '+$field+ ' y valor vacio.');
     104            return true;
     105        }else if( ( indparam != -1) && (ind == -1 ) && $value ) {
     106            if( misLeadsCF7.debug ) console.log( 'No se encuentra '+$field+ ' y pero tiene valor.');
     107            return false;
     108        /*}else if( (ind >= 0 ) && !$value ){
     109            return true;*/
     110        }else{
     111            if( misLeadsCF7.debug ) console.log( '-ELSE');
     112            return false;
     113        }
     114    }
     115   
    2116    /*
    3117    $('.wpcf7-form').submit(function(ev) {
  • mis-leads-contact-form-7/trunk/mis-leads-cf7.php

    r1724122 r1728808  
    55Description: Contecta formularios de Contact Form 7 con Mis Leads
    66Author: ohayoweb
    7 Version: 1.0
     7Version: 1.1
    88Author URI: http://www.ohayoweb.com/?utm_source=wordpress&utm_medium=plugin_uri&utm_campaign=wordpress_plugins&utm_term=mis_leads_cf7
    99*/
  • mis-leads-contact-form-7/trunk/views/admin_page.php

    r1724122 r1728808  
    6363                    </table>
    6464                   
     65                    <pre><?php print_r( self::$fields )?></pre>
    6566                   
    6667                   
Note: See TracChangeset for help on using the changeset viewer.