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? 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 URL query string parameter, anyway?
?key=value
There, that’s completely self-explanatory, right? Alright, maybe not. Let’s break it down.
We 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 the content of the webpage and bada bing. 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
So how is this useful?
You can use a query string to collect information about people who visit your website. Let’s run with the example we opened: 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.
Tracking social campaigns using a query string
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/Meta post. Next, open the Ninja Form that the link redirects to and follow the steps below.
- Add a hidden field to the form (other fields, like single-line text, will work)
- Use the merge tag selector icon to the right within the Default Value field to 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}
That’s literally it. It’s that easy.
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!
With 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 which leads are from which source, and no more struggling to associate specific data with specific submissions. Save yourself time and effort with Ninja Forms!
Tamhas says:
Using it to populate incoming ad keywords. This is awesome, thanks!! But when the customer has filled in their name and email address, I redirect them to a second page with an optional (and more detailed) Ninja Form. I want to be able to have the php query variables from the 1st Ninja Form output to the redirect address that I set in the 1st Ninja Form, so when they redirect to the page with the 2nd Ninja Form, their name and email from the 1st Form are auto-populated. Is there any way to do this please?
Quay Morgan says:
Tamhas,
Glad you got some value from the article! With what you’re describing re auto-populating a second form from the data entered into the first form, that is unfortunately not possible without custom development in version 2.9.x. It’s a feature we have integrated with Ninja Forms THREE however, so when you roll forward it will be super simple. Sorry I can’t give you a better answer now!
Cheers,
Quay
Ryan Freng says:
How do we do this in 3.0? I use the dropdown and it adds:
{query_string_key}
To the default value. Nothing else pops up. How do I tell it to use a specific key?
Quay Morgan says:
Ryan,
Hey! I just finished an updated version of this article for Ninja Forms 3.0. You can find it here:
https://ninjaforms.com/blog/pass-data-between-forms/
Cheers,
Quay
Tamhas says:
Hi Quay (cool name!), thanks for the response, only just found it now, whoops! But it’s there when i need. I will checkout your article, and have a play with NF3, which i have been using for other stuff including with Zapier add on, and is really nice, thanks!
Quay Morgan says:
haha thanks Tamhas, and no problem. We have an article up now for autopopulating a second form with field data from the first in Ninja Forms 3.0. You can find it here.
Aj Noguerra says:
Is it possible to get multiple values from the other form and pass it to the hidden field? I have tried the querystrings and it is working brilliantly, however, since I am getting the value from a form checklist, the values are being passed to the URL but the hidden field is only getting the last value as output.
Quay Morgan says:
Aj,
Yes! I just tested by making a First Name and Last Name field on Form 1, and a Name field on Form 2. I passed the values of the First Name and Last Name fields into the single Name field of the second form.
My querystring looked like this: ?keyone={field:firstname_1487014813094}&keytwo={field:lastname_1487014814043}
and the Default Value of the Name field on Form 2 looked like this: {keyone} {keytwo}
Good luck!
Cheers,
Quay
Eugene says:
Hey Nice Article. I am looking at dynamically populating a drop down field with values earlier submitted through other forms into the database. Is there an article I can read on this?
Thanks
Quay Morgan says:
Eugene,
If I’m reading you correctly, you want to pass data from the database of previously submitted forms to the dropdown field of another form? That’s probably possible with some clever custom code, but it’s not something you’ve be able to do natively within the builder. Sorry :/
Cheers,
Quay
Leslie Bloom says:
This is great, very helpful information thank you!
Has anyone tried this for tracking UTM parameters from advertising campaigns? I have multiple querystrings setup, but the form is not properly passing the information into the submission storage.
Any tips or something I might be doing wrong?
Les says:
I have been trying this all afternoon. I followed the instructions and the url shows the value when I go to my form page. I added the querystring to the hidden field but I never get the value from the source in the url.
Is this till working in 2018?
Quay Morgan says:
Les,
It does. If you’re still having issues with it, please drop us a line in our support channel!
Cheers,
Quay Morgan
Les says:
Just to clarify, The notification email I get, shows everything but the value in the URL. It doesn’t show Facebook.
Unni Krishnan says:
How to pass the country name to another form. Now is pass only for shortcode only.
Curtis Brownlee says:
Hi!
The default “Country” field currently only passes the country abbreviation. Importing a new list of countries into a Select field would allow you to set both the Label and Value to the full country name. This way, when you use a querystrings, your Value (which contains the full name) will be transferred.
I hope that this helps to guide you in the right direction.
Best Regards,
Curtis
WP Ninja
Paul Burton says:
Hi I would like to use a query string to pass a {wp:user_display_name} in a link to a ninja form and the have that users email address automatically added so it can send an email to the {wp:user_email} advising them of the submission of the form is this possible?
Quay Morgan says:
Hey! For a logged in user there wouldn’t be a need to use query strings for this; you should be able to place the {wp:user_email} tag directly into the To setting of the email action.
Cheers,
Quay
Jirapong Mukham says:
How to do this one with checkbox?
JOhann says:
Is it possible to Auto-populate Form Fields Using a value passed in the shortcode on the page?
Kathy Zant says:
Hi Johann, you can populate form fields with values sent via values sent by query string if that is helpful to you! https://ninjaforms.com/blog/how-to-auto-populate-form-fields-using-query-string/
Ros says:
I can’t seem to apply querystrings to Dropdowns. Is there a way to auto-populate dropdown fields?
Lenka Uhliarova says:
Ross,
Unfortunately it’s not possible to natively prepopulate a list field from a query string right now. The field has to have a Default Value setting to accept the passed data. This could be technically possible to do with some custom modification of the field.
Andy D says:
This feature only appears to work on “Single Line Text fields” and not on a “Number Field”. I am assuming it has been disabled as it may ultimately be possible to pass over a non-number field to it? However, would be a great feature as it would allow it to be used with your Stripe Add-on to make the Total Amount to be dynamically loaded from the query string (Especially if the input can can be controlled our side). As the stripe addon only appears to allow for a Number Field to be mapped. We wanted to put a simple Payment Link on our invoices which could pass over the Invoice Amount and Invoice Number in the querystring.
Shaylee Hansen says:
Hello Andy,
Please reach out to our customer support team, where we’d be happy to offer more assistance on this issue: https://ninjaforms.com/contact/.
Cory Moland says:
as I website possessor I believe the subject matter here is very fantastic, appreciate it for your efforts.
Simon Sandburg says:
I wanted to write you one very little remark in order to say thanks a lot yet again about the pretty techniques you’ve provided here. This is certainly remarkably generous of you to supply freely all that many people could have advertised for an e book to help with making some cash for their own end, mostly now that you could possibly have tried it in the event you desired. The secrets as well worked like the great way to fully grasp that other individuals have similar interest just like my personal own to know somewhat more on the topic of this condition. Certainly there are a lot more pleasant opportunities up front for people who look over your blog.
Cecil Masse says:
wohh precisely what I was looking for, regards for putting up.