Solved! Go to Solution.
You would place the code either in a snippet, html, or rich text on the landing page. Place <script type="text/javascript"> at the start and </script> at the end so that it is hidden, Like:
<script type="text/javascript">
MktoForms2.whenReady(function(form){
form.onSuccess(function(values, followUpUrl){
fetch('https://api.ipify.org?format=json')
.then(response => response.json())
.then(data => {
var ipAddress = data.ip;
// Update the custom field with the IP address
form.addHiddenFields({
"{{YOUR FIELD NAME}}": ipAddress
});
})
.catch(error => console.error('Error fetching IP:', error));
});
});
</script>
In your form add the field {{YOUR FIELD NAME}} to the bottom of your form, field type=hidden.
Save and approve form, approve LP, and test by filling out form.