Recently, I worked with a client who needed a straightforward lead-capture form to send submissions directly to their email. For this project, I decided to use Avada’s built-in form builder, Avada Forms, which handled the basic setup just fine. However, a few days later, my client reached out with an additional request: they wanted each form submission to include the user’s IP address and device type, all delivered within the email notification.
At first, I assumed this would be a simple adjustment since most form builders make capturing this kind of data fairly standard. But after some digging, I realized that while Avada Forms does capture IP and user agent information, it only stores it in the database and doesn’t automatically include it in notification emails. My client wasn’t thrilled with the idea of having to log in to check a database for each new lead, so I started searching for a way to make this work.
After coming up empty-handed online, I reached out to Avada’s support team, only to be met with a slow response time and limited guidance when they finally did respond. Determined to solve this for my client, I spent a few hours tinkering with different approaches and finally managed to achieve the result we needed by creating custom shortcodes to pull the IP address, device type, and browser information and include it in the email notifications.
I’m sharing these steps here in case someone else runs into the same issue and needs a straightforward way to capture and send this data in Avada Forms email notifications.
Step 1: Open Your Child Theme’s functions.php
File
It’s best to add custom code in a child theme to prevent losing your changes when Avada updates. If you’re already using a child theme, open its functions.php
file. If not, consider setting up an Avada child theme first.
- Go to Appearance > Theme Editor in your WordPress dashboard.
- Click on functions.php in the Avada child theme’s file list.
- Scroll to the bottom of the file to paste in your new code.
Step 2: Add Shortcodes for User IP, User Agent, and Device Type
To make this work, we’ll create custom shortcodes that pull in the IP address, device type, and user agent. If you’re new to shortcodes, you can check out WordPress’s shortcode documentation for a quick overview.
Next, we’ll create three shortcodes in functions.php
: one for the User IP address, one for the User Agent, and one for the Device Type.
Copy and Paste the Following Code at the end of the functions.php
file:
// Shortcode to return User IP Address
function get_user_ip_shortcode() {
return isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : 'IP not available';
}
add_shortcode('user_ip', 'get_user_ip_shortcode');
// Shortcode to return User Agent
function get_user_agent_shortcode() {
return isset($_SERVER['HTTP_USER_AGENT']) ? $_SERVER['HTTP_USER_AGENT'] : 'User agent not available';
}
add_shortcode('user_agent', 'get_user_agent_shortcode');
// Shortcode to return Device Type
function get_device_type_shortcode() {
$user_agent = strtolower($_SERVER['HTTP_USER_AGENT'] ?? '');
if (preg_match('/mobile|android|kindle|silk|fennec|iphone|ipod|blackberry|opera mini|iemobile|windows phone/i', $user_agent)) {
return 'Mobile';
}
if (preg_match('/tablet|ipad|playbook|silk/i', $user_agent)) {
return 'Tablet';
}
return 'Desktop';
}
add_shortcode('device_type', 'get_device_type_shortcode');
Explanation:
-
[user_ip]
: Captures the visitor’s IP address.[user_agent]
: Captures the browser and operating system details.[device_type]
: Identifies the visitor’s device type as Desktop, Mobile, or Tablet.
- Save the File:
- Click Update File to save your changes.
Now, the shortcodes are ready to be used in Avada Forms.
Step 3: Add Hidden Fields to Your Avada Form
With the shortcodes created, we’ll now add hidden fields to your Avada Form to capture this data and include it in email notifications.
1. Navigate to the Avada Form Editor
- Go to Avada > Forms in your WordPress dashboard.
- Select the form where you want to capture this data.
2. Set Up Each Hidden Field with Shortcode Processing
- For each piece of information (User IP, User Agent, Device Type), create a hidden field and configure it to process shortcodes.
Important: Before adding the shortcode itself, make sure to set Field Value Type to Shortcode for each hidden field. To do this:
- Click the Dynamic Content button (located next to Field Value).
- Select Shortcode to ensure the form processes the shortcode as dynamic data.
For more details on Avada’s Dynamic Content feature, you can check out their documentation.
3. Configure Each Hidden Field
- Now, with Shortcode selected, enter the following settings for each field:
Hidden Field for User IP
- Field Type: Hidden Field
- Field Label: (Optional) “User IP Address”
- Field Name:
user_ip
- Field Value:
[user_ip]
Hidden Field for User Agent
- Field Type: Hidden Field
- Field Label: (Optional) “User Agent”
- Field Name:
user_agent
- Field Value:
[user_agent]
Hidden Field for Device Type
- Field Type: Hidden Field
- Field Label: (Optional) “Device Type”
- Field Name:
device_type
- Field Value:
[device_type]
4. Save the Form
- After setting up each hidden field and configuring the Shortcode value, click Save or Update to apply your changes.
Step 4: Configure Email Notifications to Include Captured Data
To ensure that you receive this information in your form submission notifications, we’ll update the email template to display the hidden fields.
Option 1: Use [all_fields]
to Display All Form Fields
- Go to Email Notifications:
- In the form editor, navigate to the Email Notifications tab.
- Add
[all_fields]
to the Email Body:- This tag automatically includes all fields in the form, including the hidden fields for IP address, user agent, and device type.
Example Email Body:
You have received a new form submission:
[all_fields]
- Save the Email Notification:
-
- Click Save or Update to apply the changes.
Using [all_fields]
is the quickest way to include all captured data without manually listing each field.
Option 2: Use Specific Placeholders to Control Field Display
If you prefer to control which fields appear in the email, use the following placeholders:
- User IP Address:
[user_ip]
- User Agent:
[user_agent]
- Device Type:
[device_type]
Example Email Body with Specific Placeholders:
You have received a new form submission:
Name: [name]
Email: [email]
Message: [message]
User IP Address: [user_ip]
User Agent: [user_agent]
Device Type: [device_type]
- Save the Email Notification:
- Click Save or Update to apply the changes.
Step 5: Test Your Form
Finally, test your form to make sure the data is captured and displayed correctly in the email notification.
- Submit a Test Entry:
- Access your form from different devices (e.g., desktop, mobile, and tablet).
- Fill out the form and submit it.
- Verify the Email Notification:
- Check the email notification you receive to confirm the IP address, user agent, and device type display correctly.
Why This Solution Works
Avada Forms does capture information like the user’s IP address and user agent, but by default, it only saves this data to the database without including it in email notifications. For clients who prefer to receive everything in their inbox without needing to log in and check the database, this setup falls short.
By using custom shortcodes, this guide enables Avada Forms to include important data—such as IP, device type, and browser details—directly in the notification emails. With this approach, each form submission arrives with all the relevant information intact, making the process seamless and user-friendly. You can read more about IP addresses and user agents here.
Bringing User Insights Directly to Your Inbox
By following these steps, you can easily capture additional data about users in Avada Forms and include this information in email notifications. This can be valuable for analytics, troubleshooting, and understanding your audience’s device usage without requiring additional plugins or complex code.
Let us know if you have any questions or feedback, and feel free to share how this guide helped you!