How to capture IP address via WebToPerson form?

Dear Friends,

I need to capture the IP address of user who fills up the WebToPerson form and to pass this value to a custom field ‘create_ip_c’ which I have created in table ‘prospects’.

I solicit your advice & guide.

PHP: 5.4.3
SuiteCRM: 7.7.5

With thanks,

RK

Hi,


function get_client_ip() {
    $ipaddress = '';
    if ($_SERVER['HTTP_CLIENT_IP'])
        $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
    else if($_SERVER['HTTP_X_FORWARDED_FOR'])
        $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
    else if($_SERVER['HTTP_X_FORWARDED'])
        $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
    else if($_SERVER['HTTP_FORWARDED_FOR'])
        $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
    else if($_SERVER['HTTP_FORWARDED'])
        $ipaddress = $_SERVER['HTTP_FORWARDED'];
    else if($_SERVER['REMOTE_ADDR'])
        $ipaddress = $_SERVER['REMOTE_ADDR'];
    else
        $ipaddress = 'UNKNOWN';
    return $ipaddress;
}

.....

array("name" => "create_ip_c", "value" => get_client_ip() ),

1 Like

Hello Friend (item),

Thanks for your sharing the code.

Please let me know exactly where I need to insert this code? and How?

With thanks,

RK

Here is the complete code of my ‘WebToPerson’ Form:



 	<html lang='en_us'><head><base target=”_parent” /><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"></head><body><style type="text/css"><!--
 	form#WebToLeadForm, form#WebToLeadForm * {margin: 0; padding: 0; border: none; color: #333; font-size: 12px; line-height: 1.6em; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;}
 	form#WebToLeadForm {float: left; border: 0px solid #ccc; margin: 10px;}
 	form#WebToLeadForm h1 {font-size: 32px; font-weight: bold; background-color: rgb(60, 141, 188); color: rgb(247, 247, 247); padding: 10px 20px;}
 	form#WebToLeadForm h2 {font-size: 20px; font-weight: normal; background-color: rgb(255, 255, 255); color: rgb(68, 68, 68); padding: 10px 20px;}
 	form#WebToLeadForm h3 {font-size: 12px; font-weight: bold; padding: 10px 20px;}
 	form#WebToLeadForm h4 {font-size: 10px; font-weight: bold; padding: 10px 20px;}
 	form#WebToLeadForm h5 {font-size: 8px; font-weight: bold; padding: 10px 20px;}
 	form#WebToLeadForm h6 {font-size: 6px; font-weight: bold; padding: 10px 20px;}
 	form#WebToLeadForm p {padding: 10px 20px;}
 	form#WebToLeadForm input,
 	form#WebToLeadForm select,
 	form#WebToLeadForm textarea {border: 1px solid #ccc; display: block; float: left; min-width: 170px; padding: 5px;}
 	form#WebToLeadForm select {background-color: white;}
 	form#WebToLeadForm input[type="button"],
 	form#WebToLeadForm input[type="submit"] {background-color: #3267C6; font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif; font-size: 14px; font-weight: bold; color: #ffffff; display: inline; float: none; padding: 5px 10px; width: 200px; min-width: auto;}
 	form#WebToLeadForm input[type="checkbox"],
 	form#WebToLeadForm input[type="radio"] {width: 18px; min-width: auto;}
 	form#WebToLeadForm div.col {display: block; float: left; width: 330px; padding: 10px 20px;}
 	form#WebToLeadForm div.clear {display: block; float: none; clear: both; height: 0px; overflow: hidden;}
 	form#WebToLeadForm div.center {text-align: center;}
 	form#WebToLeadForm div.buttons {padding: 10px 0; border-top: 1px solid #ccc; background-color: #ffffff}
 	form#WebToLeadForm label {display: block; float: left; width: 160px; font-weight: bold;}
 	form#WebToLeadForm span.required {color: #FF0000;}
 	--></style>
 	<!-- TODO ???
 	<script type="text/javascript" src='http://localhost/luminisindia/suitecrm/cache/include/javascript/sugar_grp1.js?v=WCpISilUvngJZgJBZ4o1BA'></script>
 	--><form id="WebToLeadForm" action="http://localhost/luminisindia/suitecrm/index.php?entryPoint=WebToPersonCapture" method="POST" name="WebToLeadForm">
 	 <h2>FREE Blog Subscriptions</h2>
 	<p style="text-align: center;">Submitting this form will add you to Blog Subscription Lists. You will receive email about each new post as soon as published.</p>
 	<p><img src="http://localhost/luminisindia/images/banners/LeadManagement/Blog-Subscription-image.png" alt="" /></p>
	
	<!--My code starts here -->
	<div id="col1" style=float:left>


 	<div class="row">
 	<div class="col"><label>First Name: <span class="required">*</span></label><input name="first_name" id="first_name" type="text" required="" /></div>
 	<div class="col"> </div>
 	<div class="clear"> </div>
 	</div>
 	<div class="row">
 	<div class="col"><label>Last Name: <span class="required">*</span></label><input name="last_name" id="last_name" type="text" required="" /></div>
 	<div class="col"> </div>
 	<div class="clear"> </div>
 	</div>
 	<div class="row">
 	<div class="col"><label>Email Address: <span class="required">*</span></label><input name="email1" id="email1" type="email" required="" /></div>
 	<div class="col"> </div>
 	<div class="clear"> </div>
 	</div>
 	 
</div>



 	<div class="clear"> </div>
 	</div>
 	 
 	<input name="campaign_id" id="campaign_id" type="hidden" value="13f62ae3-f38d-fe80-a93a-57d4090f4b7d" /> 
 	<input name="assigned_user_id" id="assigned_user_id" type="hidden" value="1" /> 
 	<input name="moduleDir" id="moduleDir" type="hidden" value="Prospects" />
 	 
 	<!--my code starts here -->
 	<input name="list_name_c" id="list_name_c" type="hidden" value="hello" /></div>
 	 
 </div>
<!-- second div for column2 ends here --> 
 	</form>
 	 
 	 
 	<p>
 	<script type="text/javascript">// <![CDATA[
 	function submit_form()
 	{
 	 
 	if (typeof(validateCaptchaAndSubmit) != 'undefined')
 	{
 	validateCaptchaAndSubmit();
 	}
 	else
 	{
 	check_webtolead_fields();
 	//document.WebToLeadForm.submit();
 		 
 	}
 	 
 	 
 	}
 	 
 	 
 	function check_webtolead_fields()
 	{
 	if (document.getElementById('bool_id') != null)
 	{
 	var reqs = document.getElementById('bool_id').value;
 	bools = reqs.substring(0, reqs.lastIndexOf(';'));
 	var bool_fields = new Array();
 	var bool_fields = bools.split(';');
 	nbr_fields = bool_fields.length;
 	for (var i = 0; i < nbr_fields; i++)
 	 
 	{
 	if (document.getElementById(bool_fields[i]).value == 'on')
 	{
 	document.getElementById(bool_fields[i]).value = 1;
 	}
 	else
 	{
 	document.getElementById(bool_fields[i]).value = 0;
 	}
 	}
 	}
 	 
 	}
 	 
 	 
 	 
 	 
 	 
 	// ]]></script>
 	</p></body></html>

Please let me know exactly where I need to insert this code? and How?

Kindly help w.r.t.

Can somebody give more clear instructions?

I solicit somebody rendering his helping hand.

With thanks,

RK

1 Like

I don’t think that code is quite ready to drop in anywhere. It is PHP so it would go on the server side, in a PHP script, but not in your form html.