2017-10-11 84 views
0

我使用谷歌地理編碼的位置:Drupal的鉤子改變好好嘗試一下工作

(function ($) { 
Drupal.behaviors.ems_offices = { 
    attach: function (context, settings) { 
     geocoder = new google.maps.Geocoder(); 
     $("#edit-submit").click(function(e){ 
      var googleMapAdress  = $("#edit-field-offices-google-maps-info-und-0-value").val(); 
      var googleMapsHiddenInput = $("input[name='google_maps_geolocation']"); 
      e.preventDefault(); 

      geocoder.geocode({ 'address': googleMapAdress}, function(results, status) { 
       if (status == google.maps.GeocoderStatus.OK) { 
        if (googleMapAdress === '') { 
         googleMapsHiddenInput.val(''); 
        } else { 
         googleMapsHiddenInput.val(JSON.stringify(results)); 
        } 
       } 
      }); 

      $("#offices-node-form").submit(); 
     }); 
    } 
    }; 
}(jQuery)); 

,並試圖太勾他們* .module

function ems_offices_form_offices_node_form_alter(&$form, &$form_state, $form_id) { 
if ('offices_node_form' == $form_id) { 
    $form['#attached']['js'][] = drupal_get_path("module", "ems_offices")."/assets/js/change_address_to_google_map_object.js" ; 
    $form['#submit'][] = 'ems_offices_submit'; 
    $form['google_maps_geolocation'] = array(
     '#type'   => 'hidden', 
     '#default_value' => '', 
    ); 
} 

}

function ems_offices_submit(&$form, &$form_state) { 
    if ($_POST['google_maps_geolocation'] !== '') { 
    $googleMapsInformation              = $_POST['google_maps_geolocation']; 
    $form_state['values']['field_offices_google_maps_info']['und'][0]['value'] = $googleMapsInformation; 
    } 
} 

後調試我發現,JS腳本工作,我有JSON響應。但模塊不會收到此值。這個構建工作在我的域中的有趣部分,但本地不起作用。 哪裏可以解決問題?

+0

「但模塊沒有收到這個值」...你的意思是提交函數觸發但$ _POST ['google_maps_geolocation']是一個空字符串? 您不應該在$ form_state中檢查提交的值而不是$ _POST ['google_maps_geolocation']? – 2pha

回答

相關問題