Pre-fill input fields based on URL parameters

Hello everyone,

I’m curious if we could create custom URLs that would pre-fill an input field on a form. Can we add something like

&?input_field_1=hello
to the app URL and have that pre-fill a field, and perhaps submit it?
Eventually I would like to add custom URLs based on User Accounts, but that’s the next step.

Thanks!

1 Like

Look at the routing module of Anvil Extras. It gives you automatic parsing of URL parameters, and gives each form a distinct URL. You can do everything you’re talking about and more with it. GitHub - anvilistas/anvil-extras

Edit: if you want to see an example of using hash routing: Hash Routing Example with Templates

5 Likes

That looks great. I hope I can learn how to work with it effectively.

I guess we can’t pass parameters via URL to the app without using hash routing?

You can, but then you would need to handle it yourself rather than having it all just work. You’d need to contend with what happens if the user clicks the Back or Forward buttons in the browser, and other complexities.

If you want to go that route, the docs cover getting the hash part of the URL: Anvil Docs | Navigation

2 Likes

Ahh, ok, thank you. I agree with your assertion, I want to implement hash routing, but in the meantime, we could use this just to, say, store some information in a variable depending on the source URL.

Hi @yet155 - yep, that looks like a job for the get_url_hash() function to me! See the link Jay posted, just grab the details in your startup form or module, and put them into variables/components/etc. Hash routing is great, but in this case it’s probably using a sledgehammer to crack a walnut.

(Edit: corrected function name, because apparently I haven’t had my caffeine yet.)

1 Like