Creating an Anonymous Survey Form for Logged In Users

Would you like to create an anonymous survey form for your logged in users? By default, WPForms will capture the user ID and the user IP address for all entries.

The default entry screen will capture the user ID if the user is logged in but will also capture the user IP address

If you want to provide a truly anonymous form, this information must not be saved. Using a custom PHP filter, you can easily disable storing these details.

In this tutorial, we’ll walk you through each step of creating an anonymous form for logged-in users on your site.


Creating Your Form

First, we’ll need to create a new survey form. If you need any help creating a survey form, please review this documentation.

Start by creating your survey form. To keep it truly anonymous, just omit the Name or Email form fields.

Note: Remember to omit the Name and Email form fields from your form so that it remains 100% anonymous.

Adding PHP to Keep the Form Anonymous for Logged In Users

Now, it’s time to add the code snippet to remove the user ID and the IP address from the entry. If you need help adding code snippets to your site, please review this tutorial.

/**
 * Remove user ID and IP address from form entry.
 *
 * @link   https://wpforms.com/developers/wpforms_process_filter/
 */
  
function wpf_dev_entry_save_args( $args, $form_data ) {
   
    // Only run on my form with ID = 143, remember to change this to match your form ID
    if( $form_data[ 'id' ] != 143 ) {
        return $args;
    }
   
    $args[ 'user_id' ] = '';
    $args[ 'ip_address' ] = '';
     
    return $args;
  
}
add_filter( 'wpforms_entry_save_args', 'wpf_dev_entry_save_args', 10, 2 );

The code will only run on the form ID 143, then it will reset the user_id and ip_address to empty as it runs through before saving the entry.

Now you have a fully anonymous form for logged in users

Please remember to update the 143 in the snippet to match your own form ID. If you need assistance finding your form ID, please check out this tutorial.

That’s it! You’ve now learned how to disable user ID and user IP address tracking in WPForms entries.

Next, would you like to add some styling to your Likert Scale? Take a look at our article on How to Customize the Likert Scale Field Table.

Filter Reference: wpforms_entry_save_args