Quantcast
Channel: WordPress Tutorials Archives - Formidable Forms
Viewing all articles
Browse latest Browse all 533

Create Maps from Form Entries

$
0
0

MapPress is a free plugin that creates Google maps. You may have a form that collects address information that you want to generate a map from. This is handy with business listings, real estate listings, and many others.

  1. Install plugins. If you haven’t already, you need to install Formidable Pro and MapPress. The pro version of Formidable is needed for the custom display feature.
  2. Create your form. First, you need a form to collect the addresses you want to use in your maps. You can use any number of fields for your address that you would like. One field for the whole address, or multiple fields to separate out the city and state.
  3. Add a new shortocode. Copy and paste the following code into a new plugin or your theme functions.php file. If your not sure where to add it, put it add the very end of your functions.php right before the ending ?> if there is one. This doesn’t need any modification or changes.
    add_shortcode('form_to_mappress', 'form_to_mappress');
    function form_to_mappress($atts) {
         extract(shortcode_atts(array(
    	      'width' => 600, 'title' => '', 'body' => '',
                  'address1' => '', 'address2' => '', 'directions' => 'none'
         ), $atts));
    
         $mymap = new Mappress_Map(array("width" => $width));
         $mypoi_1 = new Mappress_Poi(array("title" => $title, "body" => $body, "address" => $address1));
         $mypoi_1->geocode();
         $mymap->pois = array($mypoi_1);
         if($address2 != ''){
           $mypoi_2 = new Mappress_Poi(array("address" => $address2));
           $mypoi_2->geocode();
           $mymap->pois = $mypoi_2;
         }
         return $mymap->display(array('directions' => $directions));
    }
  4. Create your custom display. Now, create a custom display to loop through your entries and display them on a page. The specific settings for your custom display don’t matter. In the spot you would like to insert your map, use the new shortcode you just created above.
    [form_to_mappress address1="[25]” address2=”[26]” title=”[27]” body=”[28]” width=300 directions=”google”]
    [25], [26], [27], and [28] should be replaced with field IDs or keys for your form using the dropdowns above the content/dynamic content boxes. If you only want a single point on the map, your shortcode might look like this: [form_to_mappress address1="[25]“]

    The “directions” parameter accepts “inline”, “google”, or “none”. Choose “inline” to include a link in each map marker for directions or “google” to display a directions window from Google.

    Or, if you are using multiple fields to collect your address information:
    [form_to_mappress address1="[25], [31], [32]“]
    [25] = Address line
    [31] = City
    [32] = State

    This shortcode will work independent of Formidable as well if you want to hardcode an address.
    [form_to_mappress address1="500 chestnut st, phildelphia" width="400" title="DC" body="Beautiful Washington, DC"]

  5. Publish. There are a number of ways you might be publishing: automatically in generated posts, automatically using the settings in the custom display, or by inserting the shortcode on a page. If you are inserting the shortcode, you MUST include a parameter to tell Formidable to run the content through WordPress filters, filter=1.
    [ display-frm-data id=x filter=1]

Viewing all articles
Browse latest Browse all 533

Latest Images

Trending Articles



Latest Images