Hello @Sharpharp1
Basically this script retrieves back the client IP and sets it into a data label with name in yellow.
Note that NAT still causes the IP to show the external network interfaces IP. Not the computer’s IP.
Method
Add the following in a data label with the literal property selected
<script type="text/javascript">$.getJSON("http://jsonip.com?callback=?", function (data) {SourceCode.Forms.Controls.Web.Label._getInstance($("spansname='Data Label']").attr("id")).SFCLabel('option', "text", data.ip);});</script>
Hi Mivaro
Thanks for the script. The scrip displays the IP address, but then how do you save it?
If i try and do a create method and include the data label, it tries to save the script, rather than the actual IP address.
If IP is a Text field in the smo, you get error: "The property has a long value for type Text. the maximum length allowed is 100 characters"
Any ideas?
I just added a transfer data rule from the datalabel to a textbox and was able to save the text value only. Perhaps try that?
Hi,
Still not having it with transferring datalable to textbox
My setup is as follows:
1) On Form canvas i have an empty text box and a datalable with the expression containing your script... This displays the IP fine
2) Then i have a rule When the form is initialized
Transfer data - transfer the data label to the text box
This does not work - it transfers the script to the textbox
EDIT: Did a few tests, if i add a button and on the form and use that to do the transfer it works, so it must be LAG when your script is running. Using the initialized rule to do the transfer, i can visibily see the transfer taking place before the IP address appears in the data label... would this cause the script to be copied over rather than the value?
Also tried using teh Initalized rule to do the transfer, that doesn't work either.
The reason you got the script, rather than the IP, is the script gets dropped into the data label and executed. While the script is running, you transfer its value to the text box. The script finishes and updates the value of the data label, but too late as your speedy form has already transferred the previous value of the data label.
If you want this to work, add a When Data Label is changed rule to transfer the IP value, but this script directly targets a Text Box called "Text Box". You can skip the "SourceCode.Forms.Controls.Web.Label._getInstance ...attr('id')", this is the same.
<script type="text/javascript">
$.getJSON("https://jsonip.com?callback=?",
function (data)
{$("[name='Text Box']").SFCTextBox('option', "text", data.ip);});
</script>
A final tip, if you want to run a script more than once, you need two data labels, one with the script and a blank destination. Each time you blank the destination and transfer the script, it will run the script again.
Hi,
I know this is an old ticket, but i’m using this for a new concept whereby I would like to lockdown access to a form if it’s not from on-site for example.
Using the script and accessing the form onsite, I can get the IP in the correct format xxx.xxx.xxx.xxx and that works fine to pass into rules etc.
However when i try and access the form externally, i’m getting the IP as ipV6 xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx:xxxx
Is there any way I can get the external IP address in IPv4 xxx.xxx.xxx.xxx so I can also include external IPs as well?
Thanks