Viewing 9 replies - 1 through 9 (of 9 total)
  • Plugin Author Michael Simpson

    (@msimpson)

    I assume that address and zip are other fields in the form.

    (1) You could add Javascript/JQuery to populate that hidden field in the browser

    or

    (2) After submission you can have CFDB generate that field. See http://cfdbplugin.com/?page_id=747

    You’d add something like this

    $formData->posted_data['location'] =
            'a href="http://maps.google.com/maps?q=' .
            urlencode($formData->posted_data['location']) . '+' .
            urlencode($formData->posted_data['zip']) .
            '" "target="">Location Map</a>';
    Thread Starter rjmonday

    (@rjmonday)

    Hey Michael, Thanks a bunch!

    I think I’m very close 🙂 Got address/zip to consolidate in CFDB location field but its not a hyperlink. What did i miss?

    Loaded plugin and entered:

    function myFilter($formData){
        $formName = 'Melbourne - Estimate Request'; // change this to your form's name
        if ($formData && $formName == $formData->title) {
            // Create a consolidated "location" field
           $formData->posted_data['location'] =
            '<a href="http://maps.google.com/maps?q=' .
            urlencode($formData->posted_data['address']) . '+' .
            urlencode($formData->posted_data['zip']) .
            '" "target="">Location Map</a>';
    
        }
        return $formData;
    }
    
    add_filter('cfdb_form_data', 'myFilter');
    Plugin Author Michael Simpson

    (@msimpson)

    Oh yeah, I forgot it is treated as text to users from injecting spam links into your displayed short code data.

    Let’s say we change that to just save the link without the A tag:

    $formData->posted_data['location'] =
            'http://maps.google.com/maps?q=' .
            urlencode($formData->posted_data['location']) . '+' .
            urlencode($formData->posted_data['zip']);

    That will still just display as text. But if you are using a short code to display it, you could add some jQuery to the page to make that an A tag.
    http://cfdbplugin.com/?p=867

    <script type="text/javascript">// <![CDATA[
    (function ($) {
        $('td[title="location"] div').each(
                function () {
                    $(this).html('<a target="gmap" href="' + $(this).html() + '">' + $(this).html() + '</a>');
                })
    })(jQuery);
    // ]]></script>

    or maybe just have the word “map” that is a link:

    <script type="text/javascript">// <![CDATA[
    (function ($) {
        $('td[title="location"] div').each(
                function () {
                    $(this).html('<a  target="gmap" href="' + $(this).html() + '">' + 'map</a>');
                })
    })(jQuery);
    // ]]></script>

    PS. You won’t be able to make it clickable in the admin page.

    PS. You can add this script tag to the AFTER section of a short code, e.g.

    [cfdb-table form="myform"]
    {{AFTER}}
    <script ...... </script>
    {{/AFTER}}
    [/cfdb-table]
    Thread Starter rjmonday

    (@rjmonday)

    Michael, really appreciate your time. Yes, I was thinking i might get it clickable on the admin page.

    Ok… on the shortcode display i used.

    [cfdb-datatable form="Melbourne - Estimate Request" show="Submitted,name,address,city,zip,phone,email,your-message,location" orderby="Submitted DESC"]{{AFTER}}<script type="text/javascript">// <![CDATA[
    (function ($) {
        $('td[title="location"] div').each(
                function () {
                    $(this).html('<a target="gmap" href="' + $(this).html() + '">' + $(this).html() + '</a>');
                })
    })(jQuery);
    // ]]></script>{{/AFTER}}[/cfdb-datatable]

    But the output i get is this as a clickable link not the table with location/gmap link.

    <script type=”text/javascript”>// <![CDATA[ (function ($) { $(‘td[title=”location”] div’).each( function () { $(this).html(‘<a target=”gmap” href=”‘ + $(this).html() + ‘”>’ + $(this).html() + ‘</a>’); }) })(jQuery); // ]]></script>

    Plugin Author Michael Simpson

    (@msimpson)

    Not sure I follow. Try just putting the script code after the short code instead of inside with AFTER

    Thread Starter rjmonday

    (@rjmonday)

    All set that worked.

    Thank you very much.

    Thread Starter rjmonday

    (@rjmonday)

    Hi Michael,

    How would i change this to add additional forms?

    function myFilter($formData){
        $formName = 'Melbourne - Estimate Request'; // change this to your form's name
        if ($formData && $formName == $formData->title) {
            // Create a consolidated "location" field
                  $formData->posted_data['location'] =
            'http://maps.google.com/maps?q=' .
            urlencode($formData->posted_data['address']) . '+' .
            urlencode($formData->posted_data['zip']);
    
        }
        return $formData;
    }
    
    add_filter('cfdb_form_data', 'myFilter');

    Thank You
    R

    Plugin Author Michael Simpson

    (@msimpson)

    function myFilter($formData) {
        // add form names here...
        $forms = array('Melbourne - Estimate Request', 'form2', 'form3'); // changed
        if ($formData && in_array($formData->title, $forms)) { // changed
            // Create a consolidated "location" field
            $formData->posted_data['location'] =
                    'http://maps.google.com/maps?q=' .
                    urlencode($formData->posted_data['address']) . '+' .
                    urlencode($formData->posted_data['zip']);
    
        }
        return $formData;
    }
    
    add_filter('cfdb_form_data', 'myFilter');
    Thread Starter rjmonday

    (@rjmonday)

    Awesome.. Thank You!

Viewing 9 replies - 1 through 9 (of 9 total)

The topic ‘Combine Fields’ is closed to new replies.