How to Auto-populate Form Fields Using a Query String

You’ve started a brilliant marketing campaign reaching across a variety of platforms: email, Twitter, Facebook, the whole gamut. Everything’s trucking along great, leads are up, sales are up, bosses are happy. What more is there to ask for?

What if I told you there’s a way to make life even easier? That there’s a really quick and simple way to learn which of those segments are turning into leads and sales the least and the most, so that you can focus your efforts accordingly?

Using Ninja Forms, there is. With the humble query string variable, you can easily identify exactly where a form submission has come from by auto-populating a form field with data contained in the link that the submitter clicked to bring them to the form. It’s data that you can get through other channels like Google Analytics, but it’s a world simpler and the data stays directly associated with the stored form submission. Check it out!

What in the World is a Query String Variable, Anyway?


There, that’s completely self explanatory, right? Alright maybe not. Let’s break it down.

query string imgWe all know how a URL works. You click on it or type it into your browser’s address bar, and a request is sent to the server that hosts the website for that page. The host server responds with content of the webpage, and badabing, your browser displays the page for you.

A query string is an extra bit of information appended onto the URL that gets passed along with the rest of the URL. It takes the form above, opening with ? to identify as a query string, and then a key/value pair that contains the relevant information. You can link multiple key/value pairs using & if you’re so inclined, like this: ?key=value&key=value

Great, So How is This Useful?

You can use a query string to collect information about people that visit your website. Let’s run with the example we opened with: you’ve got a marketing campaign in the works that reaches out to potential leads on Facebook, Twitter, and via email. To make the most of your time and energy, you want to be able to track which target audience is the most receptive to your current offers, and which is less so. If you’re using a Ninja Form to collect leads, you’re in luck!

Let’s set you up so that anyone clicking through to your form from Facebook is identified as a Facebook lead when you view the form submission.

First, append the query string ?&source=facebook to the end of the url that you publish on your Facebook post.

Next, open the Ninja Form that link redirects to and follow the steps below.

  • Add a hidden field to the form (other fields, like single line text, will work)
  • Under the Advanced section of the field settings for that field you’ll see the Default Value setting. Using the merge tag selector icon to the right within Default Value, select the querystring merge tag.
  • Replace the stock “your_key” text with your actual key; in this case, source. The Default Value should now read {querystring:source}

Want to auto-populate form fields based on specific, unique user data? Check out #NinjaForms!Click To TweetThat’s literally it. It’s that easy. Told you! Now, when someone clicks through your Facebook link and submits the form, you can view the submitted form in Submissions. You’ll be able to see that hidden field, and its default value will be facebook: the value associated with the key you put in both the URL query string and the hidden field’s default value!

peeking-ninja-300x138With this trick you can easily view traffic patterns and keep a record of them in one common location, conveniently associated with the form the information is relevant to! No more digging through information provided by third party tools, no more wondering exactly which leads are from which source, no more struggling to associate specific data with specific submissions. Save yourself time and effort with Ninja Forms!