Combine Fields
-
Like to have a hidden field called “location” in a CF7 form
and have it populated in CFDB with this string –
a href=”http://maps.google.com/maps?q=%5Baddress%5D+%5Bzip%5D”target=””>Location Map</awhich would create a clickable link.
A little unusual but any help would be great.
Thank You
Rhttps://wordpress.org/plugins/contact-form-7-to-database-extension/
-
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>';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');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]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>Not sure I follow. Try just putting the script code after the short code instead of inside with AFTER
All set that worked.
Thank you very much.
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
Rfunction 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');Awesome.. Thank You!
The topic ‘Combine Fields’ is closed to new replies.