NOTE: If you would like to capture IP addresses as well as other user analytics you might want to try the User Analytics Extension for Ninja Forms.
As the title states, this example will show you how to capture a user’s IP address when they fill out a form. Although this is the purpose, this code can be modified to add any kind of data to a Ninja Forms submission.
There are two ways that we can go about doing this: adding an “extra” value field or registering a new, custom field.
The first method adds a value that can be retrieved using $ninja_forms_processing->get_extra_value( ‘_value_id’ ), but this value will NOT be stored in the submission database NOR included in the email. You can read more about extra value fields here.
The second method creates a reusable form field that we can insert into any form. It will be stored in our submission database and emailed just like any other Ninja Forms field. This is the method we’ll be using in this post.
Before we get into the specific code example, I recommend reading over the ninja_forms_register_field documentation page.
Let’s take a look at how we go about registering our IP collection field. Note that we won’t be going over every available option here, just the ones we need to make IP collection work.v The comments should make what’s going on pretty clear.
And that’s all there is to it. It only took us 30 lines (10 of which are comments) to add our new IP collection field. Again, you can replace the IP collection specifics above with any kind of new data collection that you’d like.