Automatically Populating User Data in Forms

Our client was a large and respected youth arts-education program that offered individual music and dance lessons, group lessons and performance groups in a region that covered four school districts. We used Gravity Forms to build registration forms for parents to register their children.

Users don’t have to re-type

But parents had to type in some of the same information over and over again every time they registered their child, including addresses and phone numbers. Since every child had to be registered separately, this could be a lot of typing for some parents. Our client asked us if there was not a way to have some of this information automatically appear in the registration form.

To be able to pre-populate (or in Gravity Forms terms “dynamically populate”) that data, the data needs to be stored somewhere. So we created new custom fields for the user profile. We used Advanced Custom Fields for this, although there are several other ways that custom meta-fields may be added to the user profile.

The important thing to know is that when creating a new custom meta-field a “key” or field name is created that must be all one word in lowercase letters, with underscores and hyphens allowed. So a key or field name might be: “parent1_address_street”.

Displaying data automatically in a form

Once data is in those custom profile fields, it’s a simple matter to prepopulate in the form. First of all, the user must be logged in. Then simply add a Gravity Forms merge-tag as the default value. For instance, if you wanted to prepopulate an email field with the email of the user, you would place in the default value field: “{user:user_email}” (no quotes).

The merge tag for the user is able to use the meta key that you created when you set up the new profile fields. So in the case of our example above, we would place into the default value: “user:parent1_address_street}” (no quotes).

We did add a notice at the top of the form to the user that if they have previously created an account and would like for information to be automatically added to the form, they must log in.

How to get data in the profile?

How to get those meta-fields filled in – especially when our client had not had users creating user accounts before? First of all, we needed to determine whether the user was already login or not. If they were not logged in – which of course, at first no one was – a radio button field was displayed asking the user if they would like to create an account that would save some information to their profile that could allow it to be pre-populated in subsequent registrations. If they opted in, then the Gravity Forms user creation feed was run using the email as the username and mapping submitted data to not just the email field, but to the new custom meta-fields.

Updating data

If the user already had an account, we wanted to provide a way for them to be able to update their saved data – when they may not have understood that this data was available to them in the user profile. So if the user was logged in, they saw a radio button field near the submit button that asked them if they would like to update their saved information with the information in this form. Maybe their phone number has changed for example. If the user opted in to update data, then the Gravity Forms user update feed was run via conditional logic.

Protect sensitive data

One important consideration in this project was making sure that the website was not storing sensitive personal data. While initially, the client wanted to have the option to put children’s birthdates in, we persuaded them to use the child’s grade level instead. While personal mailing addresses and phone numbers, as well as email addresses do represent some level of personal data risk, the client and their board felt that enough of that data was fairly public that they felt safe in storing it in the website. Definitely you would never want to keep things like birthdates or Social Security numbers.

Can we automatically populate for you?

If you have a project where you would like to use dynamic population to pre-populate data in a form for your users, reach out we would be glad to help.

Contact us today to ask about help for your project!