Plugin Directory

Changeset 882944


Ignore:
Timestamp:
03/27/2014 01:36:52 PM (12 years ago)
Author:
roblesterjr
Message:

Added autodetect.

Location:
marketo-lead-tracking/trunk
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • marketo-lead-tracking/trunk/fieldmap.js

    r882442 r882944  
    33        jQuery('#wmi-btn-add').click(function( event ) {
    44            event.preventDefault();
    5             var output = '<tr valign="top">';
    6             output = output + '<th id="mktocell" scope="row"><input type="text" id="" value="" placeholder="Marketo Field Name" /></th>';
    7             output = output + '<td id="fieldcell"><input type="text" id="" value="" placeholder="Local Field Name" /><a href="#" id="wmi-btn-del" class="button" style="margin-left: 10px;">Delete</a></td>';
    8             output = output + '</tr>';
    9             jQuery('#wmi-field-mapping').append(output);
     5            addField();
    106        });
    117        jQuery('#wmi-btn-del').live('click', function( event ) {
     
    2723            //event.preventDefault();
    2824        });
     25        jQuery('#wmi-btn-detect').click(function( event ) {
     26            event.preventDefault();
     27            jQuery(this).attr('disabled',true);
     28            var url = jQuery('#detectpages').val();
     29            detectFields(url, jQuery(this));
     30        });
    2931    });
     32   
     33    function addField(val) {
     34        if (!val) val = '';
     35        var output = '<tr valign="top">';
     36        output = output + '<th id="mktocell" scope="row"><input type="text" id="" value="" placeholder="Marketo Field Name" /></th>';
     37        output = output + '<td id="fieldcell"><input type="text" id="" value="' + val + '" placeholder="Local Field Name" /><a href="#" id="wmi-btn-del" class="button" style="margin-left: 10px;">Delete</a></td>';
     38        output = output + '</tr>';
     39        jQuery('#wmi-field-mapping').append(output);
     40    }
     41   
     42    function detectFields(url, hobj) {
     43        jQuery.get(url, function(data) {
     44            var obj = jQuery(data);
     45            if (obj.find('form').attr('method') != 'POST') {
     46                alert('There is a form on this page, but it does not POST.');
     47            } else {
     48                var fields = false;
     49                jQuery.each(obj.find('input'), function() {
     50                    var a = jQuery(this).attr('name');
     51                    if (a != 's' && a != '' && a) {
     52                        addField(a);
     53                        fields = true;
     54                    }
     55                });
     56                jQuery.each(obj.find('select'), function() {
     57                    var a = jQuery(this).attr('name');
     58                    if (a != 's' && a != '' && a) {
     59                        addField(a);
     60                        fields = true;
     61                    }
     62                });
     63                jQuery.each(obj.find('textarea'), function() {
     64                    var a = jQuery(this).attr('name');
     65                    if (a != 's' && a != '' && a) {
     66                        addField(a);
     67                        fields = true;
     68                    }
     69                });
     70                if (!fields) {
     71                    alert('No compatible form fields were found on that page.');
     72                }
     73            }
     74            hobj.attr('disabled',false);
     75        });
     76    }
     77   
    3078/*} else {
    3179    alert('The Wordpress Marketo Lead Tracking plugin requires JQuery. Please include JQuery in your theme.');
  • marketo-lead-tracking/trunk/marketotracking.php

    r882464 r882944  
    44 * Plugin URI: http://www.rmlsoftwaresolutions.com/wordpress-plugins
    55 * Description: Attaches Marketo tracking code to website. Lets you map any form field to a specific field in marketo, including custom fields. NOTE: This is not a forms plugin. You use it in conjunction with your existing forms solution, or you can also use it with custom forms.
    6  * Version: 0.1
     6 * Version: 0.2
    77 * Author: Robert Lester
    88 * Author URI: http://www.rmlsoftwaresolutions.com
     
    2727function wmi_scripts() {
    2828    wp_enqueue_script( 'fieldmap.js', plugins_url() . '/marketo-lead-tracking/fieldmap.js', array(), '1.0.0', false );
     29}
     30
     31function detect_fields($page) {
     32    $dom = new DOMDocument();
     33    $html = file_get_contents('example.html');
     34   
     35    $names = array();
     36   
     37    @$dom->loadHTML($html);
     38   
     39    $in = $dom->getElementsByTagName('input');
     40    $sel = $dom->getElementsByTagName('select');
     41    $ta = $dom->getElementsByTagName('textarea');
     42   
     43    for ($i; $i < $in->length; $i++) {
     44        $attr = $in->item($i)->getAttribute('name');
     45        $names[] = $attr;
     46    }
     47    for ($i; $i < $sel->length; $i++) {
     48        $attr = $sel->item($i)->getAttribute('name');
     49        $names[] = $attr;
     50    }
     51    for ($i; $i < $ta->length; $i++) {
     52        $attr = $ta->item($i)->getAttribute('name');
     53        $names[] = $attr;
     54    }
     55   
     56    return json_encode($names);
    2957}
    3058
     
    136164                    <td colspan="2"><a href="#" id="wmi-btn-add" class="button button-primary">Add</a></td>
    137165                </tr>
     166                <tr valign="top">
     167                    <th scope="row">Autodetect fields on page:</th>
     168                    <td>
     169                    <select id="detectpages">
     170                        <?php
     171                            $posts = get_posts(array( 'posts_per_page'=>10000, 'post_status'=>'publish', 'post_type'=>'any' ));
     172                            foreach ($posts as $post) {
     173                                echo '<option value="' . get_permalink($post->ID) . '">' . $post->post_title . '</option>';
     174                            }
     175                        ?>
     176                    </select>
     177                    <a href="#" id="wmi-btn-detect" class="button">Detect</a></td>
     178                </tr>
    138179                <tr>
    139180                    <td colspan="2">For the "Local Field Name" you must enter the actual "name" attribute of the text box in the form from which you want to send the data to Marketo. Also, for this plugin to work, your forms must post.</td>
  • marketo-lead-tracking/trunk/readme.txt

    r882461 r882944  
    1616including custom fields. NOTE: This is not a forms plugin.
    1717You use it in conjunction with your existing forms solution, or you can also use it with custom forms.
     18
     19Now it will help you identify form fields on a page!
    1820
    1921== Installation ==
     
    36380.1 Initial Build
    3739
     400.2 Added form detection in admin panel. Select the page or post from the list, select detect, and it will find the form fields for you.
     41
    3842== Upgrade Notice ==
    3943
Note: See TracChangeset for help on using the changeset viewer.