2017-10-11 37 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

回答

相关问题