Hi,
I have created a Code to auto complete the Company name using Google Location.
Refer Below but it is not working can you help me with the issue:
<script src="//app-sj04.marketo.com/js/forms2/js/forms2.min.js"></script>
<script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?libraries=places"></script>
<form id="mktoForm_1627"></form>
<script>
MktoForms2.loadForm("//app-sj04.marketo.com", "023-STC-548", 1627,
function(form)
{
var formEl = form.getFormElem()[0];
var companyField = formEl.querySelector('INPUT[name="Company Name"]');
var defaultBounds = new google.maps.LatLngBounds(
new google.maps.LatLng(-90,-180),
new google.maps.LatLng(90,180)
);
var options = {
bounds: defaultBounds,
types: ['establishment']
};
autocomplete = new google.maps.places.Autocomplete(companyField, options);
google.maps.event.addListener(autocomplete, 'place_changed', function() {
// shorten object to just name
acCompanyName = autocomplete.getPlace().name;
companyField.value = acCompanyName;
// just for fun, fill website too
acWebsite = autocomplete.getPlace().website;
if (acWebsite) websiteField.value = acWebsite;
});
});
</script>
and also what is difference between Field and name in Marketo?
Message was edited by: Ravi Ansal
Solved! Go to Solution.
Those are additional fields on the autocomplete object. MktoForms2 :: Google Places Autocomplete is updated to show how to retrieve those values, at least for US addresses. You can do whatever you want with the values.
Ravi
In order to do something when the form loads, you would use the "loadForm" function in the Forms 2.0 API. Check out the forms 2.0 Documentation, Examples and API.
MktoForms2.loadForm("//app-pod.marketo.com", "123-xxx-567", 1057, function(form) {
// Call your code here to populate the company field
});
Hi John Mattos,
I think i am doing it right. But the value on the field is not populating.
Can you help me with that.
Ravi, it appears you are using my code from MktoForms2 :: Google Places Autocomplete (you really should attribute it instead of saying you "created a code").
Obviously the demo works, so there is something wrong with how you're plugging it in. Please provide your actual URL so we can see.
Re: "difference between field and name," every Marketo field has an "API name" which is the name you'll see if you inspect the form field and thus the name we always work with on the browser side.
Hi Sanford Whiteman,
I did not know that it was your code, Thank you very much for this.
it worked for me as well . But just one more question, Can I get the full address, city and state and though in Hidden fields.
And again Thanks a Ton.
Those are additional fields on the autocomplete object. MktoForms2 :: Google Places Autocomplete is updated to show how to retrieve those values, at least for US addresses. You can do whatever you want with the values.
Hello, Ive seen this link under several of your responses to questions surrounding this topic, but the url does not work.
Looks fine to me:
Thanks so much for your response. For some reason, there is a 404 error (even when I am logged into my codepen account). But thank you for including the screenshot of the code in use, I can use that!
Try this w/longer CodePen syntax: https://codepen.io/figureone/pen/GJVpNx/87a197ff38238b8b0dcca7a685bf0a09