What is URL parameter pre-filling?
Add parameters to a page link so the form opens with the amount, frequency and supporter details already filled in. Fewer fields to complete means fewer people drop off. Use this when:
Handing off from another tool: a quiz, calling or texting tool, peer-to-peer page or partner integration collects details first, then sends the supporter to your page to finish.
Emails from another platform: build a personalised link with that platform's merge fields.
Suggested amounts by audience: send past donors a higher preset amount or a monthly ask, without a separate page.
Texts, ads and QR codes: short links that open the form with an amount already chosen. These rarely need personal details in the link.
📌 Note: Amount and frequency work on the current donation form with no setup. Pre-filling personal details (name, email, phone, address) needs a script in a custom theme. The script also works on signup, petition, volunteer, feedback and event RSVP pages.
Where to start
Custom theme: stock themes can't be edited. If your site uses one, create a custom theme from it first. [Create a custom theme]
Custom code: the script is a theme customization. Test it on your own pages before a live campaign, and note where you added it so it can be reviewed if your theme changes.
Add the script to your custom theme
Skip this if you only want to preset the amount and frequency.
Go to Website > Theme > Files.
Open
layout.htmlto apply it site-wide, or a single page template to limit it to certain pages.Paste the script just before the closing
</body>tag. Press Ctrl+F and search</body>to find it.Click Save.
<!-- START: Pre-fill forms from URL parameters (NationBuilder help article) -->
<script>
(function () {
var p = new URLSearchParams(location.search);
var first = function (keys) {
for (var i = 0; i < keys.length; i++) {
var v = p.get(keys[i]);
if (v) return v;
}
};
var values = {
first_name: first(['first_name', 'first', 'fname', 'fn', 'firstname']),
last_name: first(['last_name', 'last', 'lname', 'ln', 'lastname']),
email: first(['email', 'e_mail', 'em']),
phone_number: first(['phone', 'phone_number', 'tel']),
mobile_number: first(['mobile', 'mobile_number', 'cell']),
submitted_address: first(['address', 'addr']),
address1: first(['address1', 'address', 'street']),
address2: first(['address2']),
city: first(['city', 'town']),
state: first(['state', 'county', 'region']),
zip: first(['zip', 'postcode', 'postal_code'])
};
var fill = function () {
Object.keys(values).forEach(function (key) {
if (!values[key]) return;
document.querySelectorAll('input[name$="[' + key + ']"]').forEach(function (el) {
if (el.value) return;
el.value = values[key];
/* Tell the theme the field changed, so floating labels move out of the way */
['input', 'change', 'blur'].forEach(function (type) {
el.dispatchEvent(new Event(type, { bubbles: true }));
});
});
});
};
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', fill);
} else {
fill();
}
})();
</script>
<!-- END: Pre-fill forms from URL parameters -->
The script matches fields by the end of their name, so one script covers every page type. It also tells the page each field changed, so floating labels display correctly.
Build your links
Add parameters to the end of the page address. Start with ? and join each one with &.
Parameter | What it fills | Needs the script | Example |
| Donation amount. A value matching a preset button selects it; any other value goes in the Other field. | No |
|
| One time or recurring | No |
|
| First name | Yes |
|
| Last name | Yes |
|
| Yes | ||
| Phone number | Yes |
|
| Mobile number | Yes |
|
| Single address field on signup and petition pages; first line of address on donation pages | Yes |
|
| Second line of address | Yes |
|
| City or town | Yes |
|
| State, county or region, where it's a text field | Yes |
|
| Postcode or ZIP code | Yes |
|
The script also accepts common alternatives such as fname, lname and postcode, so links built by other tools often work unchanged.
Examples
Preset a $100 donation:
https://yournation.nationbuilder.com/donate?amount=100
Pre-fill name and email, with a $50 monthly donation:
https://yournation.nationbuilder.com/donate?first_name=Jane&last_name=Doe&[email protected]&amount=50&frequency=monthly
URL-encode spaces and special characters. For example, + in an email address becomes %2B. Most email and integration tools do this for you.
Confirm it worked
Open your page with a sample link, such as the second example above. Check each value lands in the right field.
Things to know
Empty fields only: if a logged-in supporter's details are already on the form, the link won't overwrite them.
Consent boxes stay unticked: email and text opt-ins are left for the supporter to choose, so consent is always given actively.
JavaScript required: pre-filling runs in the visitor's browser. Visitors with JavaScript turned off see an empty form they can complete as normal.
⚠️ Please note: Details in a link can appear in browser history and website logs. Include personal details only where needed, and check this fits your privacy policy.
