WordPress.org

Ready to get started?Download WordPress

Forums

Events Manager
[resolved] Creating locations using separate form plugin ( e.g. formidable) (7 posts)

  1. adzay
    Member
    Posted 10 months ago #

    Hi Team,

    I am using the form plugin Formidable pro to create locations. It does this well, allowing it to be viewed on the site as a normal custom post.

    I have a problem however, while it does save the custom post "location" i don't think it registers the address details to the events manager locations table phpmyadmin.

    To explain further, after I create a location using the form and then I go the edit location screen, every thing looks fine. All fields are filled in (location town, postcode, custom fields etc). But after a second look at the location address details box( loaded from where.php i presume) I can see that the google map isn't loaded, it says "location not found" despite the fact that all the address fields are filled in.

    When i look at phpmyAdmin the following fields: location_Address,location_town,location_postcode,location_region,location_country
    .. All have 'NULL', even though they are not empty in the edit location field.

    Then I did something. in the location edit screen I added a Space ( or retyped in one of the values) and then all of a sudden the google map appeared with the location found and the fields were not NULL anymore.

    Do you know why this is?

    http://wordpress.org/extend/plugins/events-manager/

  2. angelo
    NetWebLogic Support
    Posted 10 months ago #

    although it looks like your location is saved on wp_posts it might not be saving on wp_em_locations tables ?

  3. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 10 months ago #

    2 problems with your approach for our purposes

    we use post custom fields for the info similar to the names in wp_em_locations e.g. _location_town (note the preceding _ )

    also, we save an additional record in wp_em_locations which is used for searching and linking events with locations.

  4. adzay
    Member
    Posted 10 months ago #

    Hi,

    Further investigation made me find the reason for this. In Events-manager.js there is a script at around line 540 .

    if( jQuery( "#em-location-data input#location-name" ).length > 0 ){
    		jQuery( "#em-location-data input#location-name" ).autocomplete({
    			source: EM.locationajaxurl,
    			minLength: 2,
    			focusout: function( event, ui ){
    				jQuery("input#location-id" ).val( ui.item.value );
    				return false;
    			},
    			select: function( event, ui ){
    				jQuery("input#location-id" ).val(ui.item.id).trigger('focusout');

    As you can see from this line I changed the triggers from '.change' to 'focusout' so that the function runs when the user clicks away from the field.

    Then I combined it with this that I placed in my functions.php

    function Select_location_field() {
        echo "<script>jQuery(document).ready(function(){
    
            jQuery('#location-address').on( 'focus', function( event ) {
                console.log('debug: on change fired!');
            });
    
            jQuery('#location-address').focus();
    
        });</script>";
    }
    add_action( 'admin_head-post.php', 'Select_location_field' );

    that function automatically highlights the text in #location-address field as soon as when the edit location admin screen is opened. When I click away the script runs and the map generates. Then of course I press save.

    Im wondering is there a way to make that script run automatically when a post is created outside of the admin screen?

  5. adzay
    Member
    Posted 10 months ago #

    I understand that using your built in form is the easier option, but I am using this plugin because it allows me to easily import posts from an excel/CSV file ( my file currently has 100 rows so far). It is also easier to customize.

    Taking that into mind, one Caveat to that is that I have to open a post in the edit location screen, click out from the highlighted field so that the script runs, save and then move to the next.

    In my case you can imagine it will be time consuming because I have 100 posts ( still increasing)

  6. adzay
    Member
    Posted 10 months ago #

    Sorry for the large amount of replies, honestly i am not trying to bump this up.

    On the website for the form plugin there is a action hook that runs a function after the form is made. http://formidablepro.com/knowledgebase/action-hooks/frm_after_create_entry/#kb-insert-form-data-into-second-database-table

    Each item_meta represents a field in the form. If I was to use this filter to insrt the values directly into the wp_em_locations, will the latitude/longitude calculation and map generation activate?

    add_action('frm_after_create_entry', 'copy_into_my_table', 20, 2);
    function copy_into_my_table($entry_id, $form_id){
      if($form_id == 4){ //change 4 to the form id of the form to copy
        global $wpdb;
        $values = array('col_name1' => $_POST['item_meta'][25], 'col_name2' => $_POST['item_meta'][26]);
        //replace 25 and 26 with the field ids of the Formidable form. Change col_name to the column names in your table
        $wpdb->insert('table_name', $values);
      }
    }

    If you cannot help me with this ( because it is another plugin) can you ignore this post in particular and help me with question above?

    Thanks :)

  7. Marcus
    NetWebLogic Support
    Plugin Author

    Posted 10 months ago #

    there's quite a lot of investigating involved here... you probably need to consider finding a developer to help you with this. sorry!

Reply

You must log in to post.

About this Plugin

About this Topic