+ Start a Discussion
Chris MarzellaChris Marzella 

How to capture IP address in the web to lead form using html/javascript?

Is there standard code I can copy and paste?
There is no in-built functionality but here is a sample code that you can use to capture ip address (tested)
<META HTTP-EQUIV="Content-type" CONTENT="text/html; charset=UTF-8">  <!------This is meta from your web-to-lead markup --->

<script type="application/javascript">
    var ipa;
    function getIP(json) {
        ipa = json.ip;
    function setIp(){
		document.getElementById('00NF000000DAKs6').value = ipa;
<script type="application/javascript" src="https://api.ipify.org?format=jsonp&callback=getIP"></script>


<body onload="setIp()">
<form action="https://www.salesforce.com/servlet/servlet.WebToLead?encoding=UTF-8" method="POST"> <!------contents of the form tag from your web-to-lead markup --->
<input type=hidden name="oid" value="00DF00000008YdW">
<input type=hidden name="retURL" value="http://google.com">

<label for="first_name">First Name</label><input  id="first_name" maxlength="40" name="first_name" size="20" type="text" /><br>
<label for="last_name">Last Name</label><input  id="last_name" maxlength="80" name="last_name" size="20" type="text" /><br>
<label for="email">Email</label><input  id="email" maxlength="80" name="email" size="20" type="text" /><br>
<input  id="00NF000000DAKs6" maxlength="20" name="00NF000000DAKs6" size="20" type="hidden"></input><br> <!---- Removed label for IP Address and made it's type hidden --->
<input type="submit" name="submit" >

1. I created IP Address field on Lead and added that while generating Web-to-lead markup.
2. Capturing IP address requires server side code. I used a third party service to get client IP. It's reliability is unknown. So, it is better to develop your own service to capture IP address using any service side progamming language like php or c#.