« »

TDOMF and Geo Mashup Harmony

December 13th, 2008

-> Scroll down or click here for my Geo Mashup – TDO Miniforms solution <-

So much for being on an extended vacation. For the last couple of days I have been completely engrossed in building a new website. I have fallen back into my old habits of staying up all night and coding, getting some sleep, grabbing some coffee, and coding some more. Ah, just like the good old days. The ones before the corporate machine killed any enjoyment that that behavior gave me.

Back in those days, WordPress, Joomla, and Drupal didn’t exsist. You (I) did everything by hand. You wanted a web based file manager, a web based mysql manager, or a bulletin board? You wrote it. Now, we have all of these wonderful content management systems with tons of great plugins. But, they come with their own head aches too. You want a certain kind of functionality? Time to start hacking.

Thank god for open source.

Tonight I ran into that situation. From what I have read, a lot of other people have too. So, I decided to post my solution in hopes that it helps some one else.

TDO Mini-Forms and Geo Mashup become friends.

Problem: I had decided to use TDO mini-forms, which is great, but they don’t support Geo Mashup. After seeing that there wasn’t a solution, I decided to dig through the source code. Here’s what I came up with:

This write up assumes that you have TDOMF and Geo Mashup installed on WordPress.

Getting the map form to show up on your submit page:

It was very simple to get the map to show up in the TDOMF form and populate. All I did was look at the source of the admin write post screen, paste the code inside the <div id=”geo_mashup_admin_edit” class=”postbox “> tag, copy it into a file (that I created) named geomap.php inside the plugins/tdo-mini-forms/include/ folder. Then, I included the file via the core form area of the form hacker. Now I have a fully functioning map, just like in the normal post editor. When you click that map, it populates the $geo_mashup_location (which Geo Mashup uses to populate the _geo_location field) and TDOMF submits it.

Here’s a snippit from the core form section of my form hacker:

<!– customfields-8 end –>
%%WIDGET:append-1%%
<!– widgets end –>
<?php include(“geomap.php”); ?>
<!– form buttons start –>
<table class=’tdomf_buttons’><tr>
<td><input type=”submit” value=”Preview” name=”tdomf_form1_preview” id=”tdomf_form1_preview” onclick=”tdomfSubmit1(‘preview’); return false;” /></td>
<td><input type=”submit” value=”Send” name=”tdomf_form1_send” id=”tdomf_form1_send” onclick=”tdomfSubmit1(‘post’); return false;” /></td>
</tr></table>
<!– form buttons end –>

Sweet! Now,we can now submit the data. That’s all well and good, but if there’s nothing to handle it on the other side it, doesn’t do us much good. So, let’s add some code to deal with it.

Dealing with the submitted data:

I opened up plugins/tdo-mini-forms/admin/tdomf-edit-post-panel.php and added the following on line 259 inside of the function tdomf_save_post() function:

if (isset($_POST[‘geo_mashup_location’])) {
add_post_meta($post_id, ‘_geo_location’, $_POST[‘geo_mashup_location’]);
};

The code now looks like this:

function tdomf_save_post() {
$post_id = (int) $_POST[‘post_ID’];
if($_POST[‘tdomf_flag’] == “false”) {
delete_post_meta($post_id, TDOMF_KEY_FLAG);
tdomf_log_message(“Removed post $post_id from TDOMF”);
die(“alert(‘”.sprintf(__(‘TDOMF: Post %d is no longer managed by TDOMF!’,’tdomf’),$post_id).”‘)”);
} else {
add_post_meta($post_id, TDOMF_KEY_FLAG, true, true);
if (isset($_POST[‘geo_mashup_location’])) {
add_post_meta($post_id, ‘_geo_location’, $_POST[‘geo_mashup_location’]);
};

if(isset($_POST[“tdomf_user”])) {
$user_id = $_POST[“tdomf_user”];
delete_post_meta($post_id, TDOMF_KEY_USER_ID);
add_post_meta($post_id, TDOMF_KEY_USER_ID, $user_id, true);
tdomf_log_message(“Submitter info for post $post_id added”);
die(“alert(‘”.sprintf(__(‘TDOMF: Submitter info for post %d updated’,’tdomf’),$post_id).”‘)”);
} else {

Your mileage may very. I hope it helps!

Be Sociable, Share!

25 Responses to “TDOMF and Geo Mashup Harmony”

  1. amenity says:

    Oh I’m so excited you got this to work! I got as far as map-on-form, but the location data wasn’t actually being added to the database. Can’t wait to try it!

  2. jenn says:

    Please, let me know how it works out for you.

  3. Jorge EPuñan says:

    Nop, not working for me…

    WP 2.6.5 and TDOMF 0.12.5

    It shows the map and everything but don’t save the location.

    Changed the tdomf-edit-post-panel.php and everything else wrote on your article.

    Any clues?

  4. jenn says:

    Hey Jorge,

    Have you verified that $_POST[’geo_mashup_location’] is being populated in by printing it in the preview window?

  5. jenn says:

    Are you using the stable or beta version of geo mashup?

  6. Jorge EPuñan says:

    Jenn: tnx for the reply; don’t have the preview window activated on TDOMF, and yes, is the beta version of Geo Mashup (it has to be this beta because of some features).

    Greets.

  7. Jorge Epuñan says:

    Jenn, I also had to add on Form Hacker the script for gmaps: the key, geo-mashup-admin.js and geo-mashup/JSONscriptRequest.js (otherwise the map won’t display with the include).

    I’ve enabled the preview for TDOMF and ir doesn’t save the location (the map appears reseted).

    Tnx again for your worry, greets!

  8. Mark says:

    If you go with this solution, make sure you do not use AJAX. The $_POST variable won’t be filled.

  9. Jorge Epuñan says:

    I’m not using AJAX at all… tnx.

  10. jenn says:

    Jorge,

    Mark did an awesome job of implementing this into TDOMF. Its in the new version that he released today. Its working great. I suggest you download it and try it out. You will have to make a change for it to work with the beta.

    File: widgets/tdomf-geomashup-widget.php
    in function form and function formHack
    change
    $geoMashupOpts[‘google_key’]
    to
    $geo_mashup_options->get(’overall’, ‘google_key’)

    There are 4 places that it needs to be changed. 2 in each function.

    It works for me. Hopefully, Mark will chime in if its a bad idea.

    ~jenn

  11. Jorge Epuñan says:

    looking forward on this solution; I’ll implement it and share the results.

    Tnx a lot again!

  12. Jorge Epuñan says:

    sadly doesn’t worked…

    in: tdomf-geomashup-widget.php (line 67, 71, 178 and 187)

    before: $geomashupOptions[‘google_key’]
    after: $geo_mashup_options->get(‘overall’, ‘google_key’)

    error: Fatal error: Call to a member function get() on a non-object in /wp-content/plugins/tdo-mini-forms/widgets/tdomf-geomashup-widget.php

    if I don’t change those lines (updated TDOMF):

    msg: You must configure Geo Mashup before you can use it in TDO-Mini-Forms

    Will try to change some code… maybe input directly the GMaps Key…

  13. jenn says:

    That should work. That’s how I got it to work to begin with, by putting the key value in by hand.

    If you add global $geo_mashup_options; at the beginning of that function, the error should go away.

  14. Jorge Epuñan says:

    Finally! It worked just fine; gotta make some adjustments but it is finally running as I needed. When the site releases I’ll post it here.

    Tnx again Jenn and Mark for your time and patience. Great work for the community.

    Greets from Chile.

  15. Jason Simon says:

    I really like the new Geo Mashup TDO Mini Forms integration and I am using the widget on a staging site. The map shows on Safari, but not Firefox. Any thoughts on why this might be so? I am not using the Geo Mashup beta version. Someone told me that it might have to do with the div tags.

  16. jenn says:

    The div tags sound logical.

  17. Jason Simon says:

    The plugin integration works fine with the default theme in Safari and Firefox, but it doesn’t work with my custom theme in Firefox. Could it be a theme problem rather than a widget problem? I’m kind of new to coding and such, so I don’t know much about div tags etc… and what to try first to fix it. Thanks!

  18. Carlos Cazorla says:

    Hey…

    I have the latest verison of Mini Forms 0.12.7 and the latest version of WordPress 2.7.
    Im using the widget but im having this msg:
    “You must configure Geo Mashup before you can use it in TDO-Mini-Forms”

    Anyone knows what can i do?

  19. jenn says:

    Jason,

    You might want to try using firebug to diagnose problems in firefox. With the information that you have provided, I can only assume it is a CSS problem with your theme.

    Carlos,

    What version of Geomashup are you using? If you look in my comments above, you will see that if you are using 1.2beta1 you have to make the following change to get rid of that error message:

    Open the file widgets/tdomf-geomashup-widget.php and change all occurrences of $geoMashupOpts[’google_key’] to your actual google map key.

    My comment from December has different directions (which work too), but the directions in this post are easier, so I suggest them.

  20. Denny says:

    Where can i edit tag ?
    Thank You.

  21. Denny says:

    ” tag”

  22. nicolas says:

    you have saved my life dude
    thanks

  23. kit says:

    since the upgrade of tdo mini forms the geo mashup widget doesn’t work anymore. anyone have any ideas?

  24. Sven says:

    A new version badly needed!
    A hundred bucks to the one that gets me going with a nice geo mashup widget with TDO Mini forms.

  25. recipes says:

    Geo Mashup map doesn’t show

    I didn’t see any map after I created new post direectly use wordpress posts editer or use TDO Mini Form. I do not know what is wrong.
    It asked me supply one place. but there is a place in my post or TDOFM. where the place should I supply? just in the content? or need special custom fields

    (which Custom fields)? what type address should I supply (detail address, intersection or Post Code)?

    any one can help me?
    Thank you!!

    My system:
    Wordpress V3.3.1
    Geo Mashup V1.2.10
    TDO Mini Forms V0.13.9

Leave a Reply

CommentLuv badge